update_metadata example

return new WP_Error(
                'rest_cannot_update',
                /* translators: %s: Custom field key. */
                sprintf( __( 'Sorry, you are not allowed to edit the %s custom field.' )$name ),
                array(
                    'key'    => $name,
                    'status' => rest_authorization_required_code(),
                )
            );
        }

        if ( ! update_metadata( $meta_type$object_idwp_slash( $meta_key )wp_slash( $value ) ) ) {
            return new WP_Error(
                'rest_meta_database_error',
                /* translators: %s: Custom field key. */
                sprintf( __( 'Could not update the meta value of %s in database.' )$meta_key ),
                array(
                    'key'    => $name,
                    'status' => WP_Http::INTERNAL_SERVER_ERROR,
                )
            );
        }

        

function update_term_meta( $term_id$meta_key$meta_value$prev_value = '' ) {
    if ( wp_term_is_shared( $term_id ) ) {
        return new WP_Error( 'ambiguous_term_id', __( 'Term meta cannot be added to terms that are shared between taxonomies.' )$term_id );
    }

    return update_metadata( 'term', $term_id$meta_key$meta_value$prev_value );
}

/** * Updates metadata cache for list of term IDs. * * Performs SQL query to retrieve all metadata for the terms matching `$term_ids` and stores them in the cache. * Subsequent calls to `get_term_meta()` will not need to query the database. * * @since 4.4.0 * * @param array $term_ids List of term IDs. * @return array|false An array of metadata on success, false if there is nothing to update. */

function update_user_meta( $user_id$meta_key$meta_value$prev_value = '' ) {
    return update_metadata( 'user', $user_id$meta_key$meta_value$prev_value );
}

/** * Counts number of users who have each of the user roles. * * Assumes there are neither duplicated nor orphaned capabilities meta_values. * Assumes role names are unique phrases. Same assumption made by WP_User_Query::prepare_query() * Using $strategy = 'time' this is CPU-intensive and should handle around 10^7 users. * Using $strategy = 'memory' this is memory-intensive and should handle around 10^5 users, but see WP Bug #12257. * * @since 3.0.0 * @since 4.4.0 The number of users with no role is now included in the `none` element. * @since 4.9.0 The `$site_id` parameter was added to support multisite. * * @global wpdb $wpdb WordPress database abstraction object. * * @param string $strategy Optional. The computational strategy to use when counting the users. * Accepts either 'time' or 'memory'. Default 'time'. * @param int|null $site_id Optional. The site ID to count users for. Defaults to the current site. * @return array { * User counts. * * @type int $total_users Total number of users on the site. * @type int[] $avail_roles Array of user counts keyed by user role. * } */

function update_comment_meta( $comment_id$meta_key$meta_value$prev_value = '' ) {
    return update_metadata( 'comment', $comment_id$meta_key$meta_value$prev_value );
}

/** * Sets the cookies used to store an unauthenticated commentator's identity. Typically used * to recall previous comments by this commentator that are still held in moderation. * * @since 3.4.0 * @since 4.9.6 The `$cookies_consent` parameter was added. * * @param WP_Comment $comment Comment object. * @param WP_User $user Comment author's user object. The user may not exist. * @param bool $cookies_consent Optional. Comment author's consent to store cookies. Default true. */

function wp_save_footnotes_meta( $revision_id ) {
    $post_id = wp_is_post_revision( $revision_id );

    if ( $post_id ) {
        $footnotes = get_post_meta( $post_id, 'footnotes', true );

        if ( $footnotes ) {
            // Can't use update_post_meta() because it doesn't allow revisions.             update_metadata( 'post', $revision_id, 'footnotes', wp_slash( $footnotes ) );
        }
    }
}
add_action( 'wp_after_insert_post', 'wp_save_footnotes_meta' );

/** * Keeps track of the revision ID for "rest_after_insert_{$post_type}". * * @since 6.3.0 * * @global int $wp_temporary_footnote_revision_id The footnote revision ID. * * @param int $revision_id The revision ID. */

function update_post_meta( $post_id$meta_key$meta_value$prev_value = '' ) {
    // Make sure meta is updated for the post, not for a revision.     $the_post = wp_is_post_revision( $post_id );
    if ( $the_post ) {
        $post_id = $the_post;
    }

    return update_metadata( 'post', $post_id$meta_key$meta_value$prev_value );
}

/** * Deletes everything from post meta matching the given meta key. * * @since 2.3.0 * * @param string $post_meta_key Key to search for when deleting. * @return bool Whether the post meta key was deleted from the database. */
function delete_post_meta_by_key( $post_meta_key ) {
    

function update_site_meta( $site_id$meta_key$meta_value$prev_value = '' ) {
    return update_metadata( 'blog', $site_id$meta_key$meta_value$prev_value );
}

/** * Deletes everything from site meta matching meta key. * * @since 5.1.0 * * @param string $meta_key Metadata key to search for when deleting. * @return bool Whether the site meta key was deleted from the database. */
function delete_site_meta_by_key( $meta_key ) {
    
Home | Imprint | This part of the site doesn't use cookies.