Challenge - 5 Problems
Post Meta Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate1:30remaining
What is the output of this code when retrieving post meta?
Consider a WordPress post with ID 42 that has a meta key 'color' with value 'blue'. What will be the output of the following code?
echo get_post_meta(42, 'color', true);
Wordpress
echo get_post_meta(42, 'color', true);
Attempts:
2 left
💡 Hint
The third parameter controls if the function returns a single value or an array.
✗ Incorrect
When the third parameter is true, get_post_meta returns a single value, which is the meta value 'blue'.
❓ state_output
intermediate1:30remaining
What is the value of $meta after this code runs?
Given a post with ID 10 that has two meta values for key 'tags': 'php' and 'wordpress', what is the value of $meta?
$meta = get_post_meta(10, 'tags', false);
Wordpress
$meta = get_post_meta(10, 'tags', false);
Attempts:
2 left
💡 Hint
The third parameter false returns all meta values as an array.
✗ Incorrect
When the third parameter is false, get_post_meta returns an array of all meta values for the key.
📝 Syntax
advanced2:00remaining
Which option correctly adds a post meta key 'rating' with value 5?
You want to add a meta key 'rating' with value 5 to post ID 15. Which code snippet is correct?
Attempts:
2 left
💡 Hint
Check the function parameters: post ID, meta key, meta value, and optional unique flag.
✗ Incorrect
Option B correctly uses add_post_meta with post ID as integer, meta key as string, and meta value as integer.
🔧 Debug
advanced2:00remaining
Why does this code fail to update post meta?
The developer tries to update the meta key 'views' for post ID 20 but it does not change. What is wrong?
update_post_meta(20, 'views');
Wordpress
update_post_meta(20, 'views');
Attempts:
2 left
💡 Hint
Check the function signature for update_post_meta.
✗ Incorrect
update_post_meta requires three parameters: post ID, meta key, and new meta value. Missing the value causes failure.
🧠 Conceptual
expert2:00remaining
What happens if you call get_post_meta with a non-existent meta key and third parameter true?
If you call get_post_meta(30, 'nonexistent_key', true) on a post with ID 30 that has no such meta key, what is returned?
Wordpress
get_post_meta(30, 'nonexistent_key', true);
Attempts:
2 left
💡 Hint
Check the WordPress documentation for get_post_meta return values when meta key is missing.
✗ Incorrect
When the third parameter is true and the meta key does not exist, get_post_meta returns an empty string.