get_metadata example


function get_comment_meta( $comment_id$key = '', $single = false ) {
    return get_metadata( 'comment', $comment_id$key$single );
}

/** * Queue comment meta for lazy-loading. * * @since 6.3.0 * * @param array $comment_ids List of comment IDs. */
function wp_lazyload_comment_meta( array $comment_ids ) {
    if ( empty( $comment_ids ) ) {
        

    public function get_value( $object_id$request ) {
        $fields   = $this->get_registered_fields();
        $response = array();

        foreach ( $fields as $meta_key => $args ) {
            $name       = $args['name'];
            $all_values = get_metadata( $this->get_meta_type()$object_id$meta_key, false );

            if ( $args['single'] ) {
                if ( empty( $all_values ) ) {
                    $value = $args['schema']['default'];
                } else {
                    $value = $all_values[0];
                }

                $value = $this->prepare_value_for_response( $value$request$args );
            } else {
                $value = array();

                

function get_user_meta( $user_id$key = '', $single = false ) {
    return get_metadata( 'user', $user_id$key$single );
}

/** * Updates user meta field based on user ID. * * Use the $prev_value parameter to differentiate between meta fields with the * same key and user ID. * * If the meta field for the user does not exist, it will be added. * * @since 3.0.0 * * @link https://developer.wordpress.org/reference/functions/update_user_meta/ * * @param int $user_id User ID. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. * @param mixed $prev_value Optional. Previous value to check before updating. * If specified, only update existing metadata entries with * this value. Otherwise, update all entries. Default empty. * @return int|bool Meta ID if the key didn't exist, true on successful update, * false on failure or if the value passed to the function * is the same as the one that is already in the database. */

function get_post_meta( $post_id$key = '', $single = false ) {
    return get_metadata( 'post', $post_id$key$single );
}

/** * Updates a post meta field based on the given post ID. * * Use the `$prev_value` parameter to differentiate between meta fields with the * same key and post ID. * * If the meta field for the post does not exist, it will be added and its ID returned. * * Can be used in place of add_post_meta(). * * @since 1.5.0 * * @param int $post_id Post ID. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. * @param mixed $prev_value Optional. Previous value to check before updating. * If specified, only update existing metadata entries with * this value. Otherwise, update all entries. Default empty. * @return int|bool Meta ID if the key didn't exist, true on successful update, * false on failure or if the value passed to the function * is the same as the one that is already in the database. */

function get_site_meta( $site_id$key = '', $single = false ) {
    return get_metadata( 'blog', $site_id$key$single );
}

/** * Updates metadata for a site. * * Use the $prev_value parameter to differentiate between meta fields with the * same key and site ID. * * If the meta field for the site does not exist, it will be added. * * @since 5.1.0 * * @param int $site_id Site ID. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. * @param mixed $prev_value Optional. Previous value to check before updating. * If specified, only update existing metadata entries with * this value. Otherwise, update all entries. Default empty. * @return int|bool Meta ID if the key didn't exist, true on successful update, * false on failure or if the value passed to the function * is the same as the one that is already in the database. */

function get_term_meta( $term_id$key = '', $single = false ) {
    return get_metadata( 'term', $term_id$key$single );
}

/** * Updates term metadata. * * Use the `$prev_value` parameter to differentiate between meta fields with the same key and term ID. * * If the meta field for the term does not exist, it will be added. * * @since 4.4.0 * * @param int $term_id Term ID. * @param string $meta_key Metadata key. * @param mixed $meta_value Metadata value. Must be serializable if non-scalar. * @param mixed $prev_value Optional. Previous value to check before updating. * If specified, only update existing metadata entries with * this value. Otherwise, update all entries. Default empty. * @return int|bool|WP_Error Meta ID if the key didn't exist. true on successful update, * false on failure or if the value passed to the function * is the same as the one that is already in the database. * WP_Error when term_id is ambiguous between taxonomies. */
if ( ! empty( $object_subtype ) && ! registered_meta_key_exists( $object_type$meta_key$object_subtype ) ) {
            $object_subtype = '';
        }

        if ( ! registered_meta_key_exists( $object_type$meta_key$object_subtype ) ) {
            return false;
        }

        $meta_keys     = get_registered_meta_keys( $object_type$object_subtype );
        $meta_key_data = $meta_keys[ $meta_key ];

        $data = get_metadata( $object_type$object_id$meta_key$meta_key_data['single'] );

        return $data;
    }

    $data = get_metadata( $object_type$object_id );
    if ( ! $data ) {
        return array();
    }

    $meta_keys = get_registered_meta_keys( $object_type );
    if ( ! empty( $object_subtype ) ) {
        

function wp_get_footnotes_from_revision( $revision_field$field$revision ) {
    return get_metadata( 'post', $revision->ID, $field, true );
}
add_filter( '_wp_post_revision_field_footnotes', 'wp_get_footnotes_from_revision', 10, 3 );

/** * The REST API autosave endpoint doesn't save meta, so we can use the * `wp_creating_autosave` when it updates an exiting autosave, and * `_wp_put_post_revision` when it creates a new autosave. * * @since 6.3.0 * * @param int|array $autosave The autosave ID or array. */
Home | Imprint | This part of the site doesn't use cookies.