Bird
0
0

Given the code snippet:

medium📝 component behavior Q13 of 15
Wordpress - Custom Fields and Meta Data
Given the code snippet:
$value = get_post_meta(10, 'price', true);
echo $value;

What will be the output if the custom field 'price' for post ID 10 is set to '25.99'?
AError: Undefined variable
BArray
CNULL
D25.99
Step-by-Step Solution
Solution:
  1. Step 1: Understand get_post_meta() with single=true

    When the third parameter is true, get_post_meta() returns a single value as a string, not an array.
  2. Step 2: Check the stored value for 'price'

    The custom field 'price' for post ID 10 is '25.99', so echoing $value outputs '25.99'.
  3. Final Answer:

    25.99 -> Option D
  4. Quick Check:

    Single meta value output = 25.99 [OK]
Quick Trick: Use true to get single value, not array [OK]
Common Mistakes:
  • Expecting an array instead of a string
  • Not setting the third parameter to true
  • Assuming NULL if value exists

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes