get_metadata_by_mid example


    $check = apply_filters( "update_{$meta_type}_metadata_by_mid", null, $meta_id$meta_value$meta_key );
    if ( null !== $check ) {
        return (bool) $check;
    }

    // Fetch the meta and go on if it's found.     $meta = get_metadata_by_mid( $meta_type$meta_id );
    if ( $meta ) {
        $original_key = $meta->meta_key;
        $object_id    = $meta->{$column};

        /* * If a new meta_key (last parameter) was specified, change the meta key, * otherwise use the original key in the update statement. */
        if ( false === $meta_key ) {
            $meta_key = $original_key;
        } elseif ( ! is_string( $meta_key ) ) {
            


/** * Handles deleting meta via AJAX. * * @since 3.1.0 */
function wp_ajax_delete_meta() {
    $id = isset( $_POST['id'] ) ? (int) $_POST['id'] : 0;

    check_ajax_referer( "delete-meta_$id);
    $meta = get_metadata_by_mid( 'post', $id );

    if ( ! $meta ) {
        wp_die( 1 );
    }

    if ( is_protected_meta( $meta->meta_key, 'post' ) || ! current_user_can( 'delete_post_meta', $meta->post_id, $meta->meta_key ) ) {
        wp_die( -1 );
    }

    if ( delete_meta( $meta->meta_id ) ) {
        wp_die( 1 );
    }


/** * Returns post meta data by meta ID. * * @since 2.1.0 * * @param int $mid * @return object|bool */
function get_post_meta_by_id( $mid ) {
    return get_metadata_by_mid( 'post', $mid );
}

/** * Returns meta data for the given post ID. * * @since 1.2.0 * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $postid A post ID. * @return array[] { * Array of meta data arrays for the given post ID. * * @type array ...$0 { * Associative array of meta data. * * @type string $meta_key Meta key. * @type mixed $meta_value Meta value. * @type string $meta_id Meta ID as a numeric string. * @type string $post_id Post ID as a numeric string. * } * } */

    public function set_custom_fields( $post_id$fields ) {
        $post_id = (int) $post_id;

        foreach ( (array) $fields as $meta ) {
            if ( isset( $meta['id'] ) ) {
                $meta['id'] = (int) $meta['id'];
                $pmeta      = get_metadata_by_mid( 'post', $meta['id'] );

                if ( ! $pmeta || $pmeta->post_id != $post_id ) {
                    continue;
                }

                if ( isset( $meta['key'] ) ) {
                    $meta['key'] = wp_unslash( $meta['key'] );
                    if ( $meta['key'] !== $pmeta->meta_key ) {
                        continue;
                    }
                    $meta['value'] = wp_unslash( $meta['value'] );
                    
Home | Imprint | This part of the site doesn't use cookies.