Bird
0
0

You want to update a post meta key 'views' to increase its count by 1 for post ID 10. Which code snippet correctly does this?

hard📝 state output Q15 of 15
Wordpress - Custom Fields and Meta Data
You want to update a post meta key 'views' to increase its count by 1 for post ID 10. Which code snippet correctly does this?
Aupdate_post_meta(10, 'views', get_post_meta(10, 'views', true) + 1);
Badd_post_meta(10, 'views', 1);
Cget_post_meta(10, 'views', true) + 1;
Ddelete_post_meta(10, 'views'); update_post_meta(10, 'views', 1);
Step-by-Step Solution
Solution:
  1. Step 1: Retrieve current 'views' meta value

    Use get_post_meta(10, 'views', true) to get current count.
  2. Step 2: Add 1 and update meta

    Increase count by 1 and update with update_post_meta(10, 'views', new_value).
  3. Final Answer:

    update_post_meta(10, 'views', get_post_meta(10, 'views', true) + 1); -> Option A
  4. Quick Check:

    Increment meta by get + 1 then update [OK]
Quick Trick: Get current value, add 1, then update meta [OK]
Common Mistakes:
  • Using add_post_meta instead of update_post_meta
  • Not retrieving current meta value before increment
  • Deleting meta unnecessarily

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes