Complete the code to add a post meta value in WordPress.
add_post_meta($post_id, '[1]', 'blue');
The first argument after $post_id is the meta key. Here, 'color' is the meta key to store the value 'blue'.
Complete the code to retrieve a post meta value.
$color = get_post_meta($post_id, '[1]', true);
The second argument is the meta key to retrieve. 'color' matches the key used when saving the meta.
Fix the error in the code to update a post meta value.
update_post_meta($post_id, 'color', [1]);
The value to update must be a variable or a string. Here, $new_color is a variable holding the new value.
Fill both blanks to delete a post meta key and then add a new meta value.
delete_post_meta($post_id, [1]); add_post_meta($post_id, [2], 'green');
First, delete the old meta key 'color'. Then add a new meta key 'color_code' with the value 'green'.
Fill all three blanks to create a meta box callback that displays a text input for a post meta key.
function my_meta_box_callback($post) {
$value = get_post_meta($post->ID, [1], true);
echo '<label for="my_meta_field">Color:</label>';
echo '<input type="text" id="my_meta_field" name=[2] value="' . esc_attr($value) . '" />';
wp_nonce_field([3], 'my_meta_nonce');
}The meta key is 'color'. The input name must match the meta field name 'my_meta_field'. The nonce action is a unique string like 'my_meta_nonce_action' for security.