update_metadata_by_mid example

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'] );
                    if ( current_user_can( 'edit_post_meta', $post_id$meta['key'] ) ) {
                        update_metadata_by_mid( 'post', $meta['id']$meta['value'] );
                    }
                } elseif ( current_user_can( 'delete_post_meta', $post_id$pmeta->meta_key ) ) {
                    delete_metadata_by_mid( 'post', $meta['id'] );
                }
            } elseif ( current_user_can( 'add_post_meta', $post_idwp_unslash( $meta['key'] ) ) ) {
                add_post_meta( $post_id$meta['key']$meta['value'] );
            }
        }
    }

    /** * Retrieves custom fields for a term. * * @since 4.9.0 * * @param int $term_id Term ID. * @return array Array of custom fields, if they exist. */
        }

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

        if ( $meta->meta_value != $value || $meta->meta_key != $key ) {
            $u = update_metadata_by_mid( 'post', $mid$value$key );
            if ( ! $u ) {
                wp_die( 0 ); // We know meta exists; we also know it's unchanged (or DB error, in which case there are bigger problems).             }
        }

        $x = new WP_Ajax_Response(
            array(
                'what'         => 'meta',
                'id'           => $mid,
                'old_id'       => $mid,
                'data'         => _list_meta_row(
                    

function update_meta( $meta_id$meta_key$meta_value ) {
    $meta_key   = wp_unslash( $meta_key );
    $meta_value = wp_unslash( $meta_value );

    return update_metadata_by_mid( 'post', $meta_id$meta_value$meta_key );
}

// // Private. //
/** * Replaces hrefs of attachment anchors with up-to-date permalinks. * * @since 2.3.0 * @access private * * @param int|object $post Post ID or post object. * @return void|int|WP_Error Void if nothing fixed. 0 or WP_Error on update failure. The post ID on update success. */
Home | Imprint | This part of the site doesn't use cookies.