0
0
Wordpressframework~10 mins

Post meta basics in Wordpress - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a post meta value in WordPress.

Wordpress
add_post_meta($post_id, '[1]', 'blue');
Drag options to blanks, or click blank then click option'
Atitle
Bdate
Cauthor
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a WordPress core field like 'title' as meta key.
Leaving the meta key blank.
Confusing meta key with meta value.
2fill in blank
medium

Complete the code to retrieve a post meta value.

Wordpress
$color = get_post_meta($post_id, '[1]', true);
Drag options to blanks, or click blank then click option'
Adate
Bcontent
Ccolor
Dauthor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different meta key than the one used to save the meta.
Omitting the third argument and getting an array instead of a string.
3fill in blank
hard

Fix the error in the code to update a post meta value.

Wordpress
update_post_meta($post_id, 'color', [1]);
Drag options to blanks, or click blank then click option'
A$new_color
B'new_color'
Cnew_color
Dcolor
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string literal instead of a variable for the new value.
Forgetting the dollar sign for variables.
4fill in blank
hard

Fill both blanks to delete a post meta key and then add a new meta value.

Wordpress
delete_post_meta($post_id, [1]);
add_post_meta($post_id, [2], 'green');
Drag options to blanks, or click blank then click option'
A'color'
B'author'
C'color_code'
D'date'
Attempts:
3 left
💡 Hint
Common Mistakes
Deleting a meta key that does not exist.
Using the same meta key for both delete and add when intending to change the key name.
5fill in blank
hard

Fill all three blanks to create a meta box callback that displays a text input for a post meta key.

Wordpress
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');
}
Drag options to blanks, or click blank then click option'
A'color'
B'my_meta_field'
C'my_meta_nonce_action'
D'color_code'
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching the meta key and input name.
Omitting the nonce field or using an incorrect nonce action string.