Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Wordpress - Custom Fields and Meta Data
Identify the error in this code snippet:
echo get_post_meta('price', 15, true);
AFunction get_post_meta() does not exist
BMissing third parameter
CParameters are in wrong order
DPost ID must be a string
Step-by-Step Solution
Solution:
  1. Step 1: Check parameter order in get_post_meta()

    The correct order is get_post_meta($post_id, $key, $single). Here, 'price' (key) is first and 15 (post ID) second, which is wrong.
  2. Step 2: Confirm other options are incorrect

    The third parameter is present, the function exists, and post ID should be an integer, not string.
  3. Final Answer:

    Parameters are in wrong order -> Option C
  4. Quick Check:

    Post ID first, key second in get_post_meta() [OK]
Quick Trick: Post ID always comes before key in get_post_meta() [OK]
Common Mistakes:
  • Swapping post ID and key parameters
  • Assuming post ID can be string
  • Omitting required parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes