Bird
0
0

What will this code output if the post has a metadata key 'color' with value 'blue'?

medium📝 component behavior Q13 of 15
Wordpress - Custom Fields and Meta Data
What will this code output if the post has a metadata key 'color' with value 'blue'?
echo get_post_meta($post_id, 'color', true);
Anull
Bcolor
CArray
Dblue
Step-by-Step Solution
Solution:
  1. Step 1: Understand get_post_meta() usage

    get_post_meta() with third parameter true returns the single metadata value for the key.
  2. Step 2: Check metadata value

    The key 'color' has value 'blue', so the function returns 'blue'.
  3. Final Answer:

    blue -> Option D
  4. Quick Check:

    get_post_meta() returns stored value 'blue' [OK]
Quick Trick: get_post_meta() with true returns single value [OK]
Common Mistakes:
  • Expecting the key name instead of value
  • Thinking it returns an array without true parameter
  • Assuming null if metadata exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes