Bird
0
0

What will this code output if the custom field 'rating' does not exist for post 10?

medium📝 component behavior Q5 of 15
Wordpress - Custom Fields and Meta Data
What will this code output if the custom field 'rating' does not exist for post 10?
$value = get_post_meta(10, 'rating', true);
echo $value;
A0
BEmpty string
CError message
DNULL
Step-by-Step Solution
Solution:
  1. Step 1: Behavior when meta key missing

    get_post_meta returns empty string if key not found and single=true.
  2. Step 2: Echo output

    Echoing empty string outputs nothing visible but no error.
  3. Final Answer:

    Outputs an empty string -> Option B
  4. Quick Check:

    Missing key returns empty string with single=true [OK]
Quick Trick: Missing key with true returns empty string, not error [OK]
Common Mistakes:
  • Expecting zero or NULL
  • Assuming error thrown
  • Confusing with array return

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes