Bird
0
0

A developer writes this code to create a post but gets an error: wp_insert_post('My Title'); What is the problem?

medium📝 Debug Q7 of 15
Wordpress - Content Management
A developer writes this code to create a post but gets an error: wp_insert_post('My Title'); What is the problem?
AThe post title must be set with 'title' key, not directly.
Bwp_insert_post() requires an array, not a string.
CThe function cannot create posts without content.
DThe post status must be 'publish' explicitly.
Step-by-Step Solution
Solution:
  1. Step 1: Check wp_insert_post() parameter type

    wp_insert_post() expects an array of post data, not a string.
  2. Step 2: Identify error cause

    Passing a string causes a type error because the function cannot parse it as post data.
  3. Final Answer:

    Function requires an array, not a string -> Option B
  4. Quick Check:

    wp_insert_post needs array input [OK]
Quick Trick: Pass an array with keys to wp_insert_post() [OK]
Common Mistakes:
  • Passing string instead of array
  • Using wrong key names
  • Omitting required keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes