Bird
0
0

Which of the following is the correct way to programmatically create a new post in WordPress using PHP?

easy📝 Syntax Q3 of 15
Wordpress - Content Management
Which of the following is the correct way to programmatically create a new post in WordPress using PHP?
A$post_id = wp_insert_post(array('post_title' => 'My Post', 'post_content' => 'Content here', 'post_status' => 'publish'));
B$post_id = wp_create_post('My Post', 'Content here');
Cinsert_post('My Post', 'Content here', 'publish');
Dwp_add_post('My Post', 'Content here', 'publish');
Step-by-Step Solution
Solution:
  1. Step 1: Identify WordPress function for inserting posts

    wp_insert_post() is the correct WordPress function to create posts programmatically.
  2. Step 2: Check function parameters

    The function accepts an array with keys like 'post_title', 'post_content', and 'post_status'. Other options are not valid WordPress functions.
  3. Final Answer:

    Using wp_insert_post with an array of post data -> Option A
  4. Quick Check:

    Correct function to create post = wp_insert_post [OK]
Quick Trick: Use wp_insert_post() with an array to create posts in PHP [OK]
Common Mistakes:
  • Using non-existent functions
  • Passing parameters incorrectly
  • Missing post_status key

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Wordpress Quizzes