In WordPress, when you create a new post and save it with the status set to 'draft', what is the expected behavior?
Think about what 'draft' means in everyday writing before sharing.
Saving a post as a draft means it is stored but not shown publicly. You can edit it later and publish when ready.
Choose the correct PHP function call to create a new post in WordPress with the title 'Hello World' and content 'Welcome to my blog'.
Look for the official WordPress function that inserts posts.
The function wp_insert_post is the correct WordPress function to create posts programmatically. Other options are not valid WordPress functions.
Given this PHP code snippet to update a post's content (assuming post ID 42 exists), what happens?
$post_id = 42; $post_data = ['ID' => $post_id, 'post_content' => 'New content here']; wp_insert_post($post_data);
$post_id = 42; $post_data = ['ID' => $post_id, 'post_content' => 'New content here']; wp_insert_post($post_data);
Recall that wp_insert_post can update existing posts if the 'ID' is provided and the post exists.
The code works correctly. When the 'ID' key is included in the array passed to wp_insert_post, and the post exists, it updates the specified fields like post_content while preserving other data such as post_status.
Consider this code snippet:
$result = wp_update_post(['ID' => 999999, 'post_content' => 'Updated content']);
Assuming post ID 999999 does not exist, what is the value of $result?
$result = wp_update_post(['ID' => 999999, 'post_content' => 'Updated content']);
Check the WordPress documentation for wp_update_post return values on failure.
wp_update_post returns 0 if the post ID does not exist or update fails. It returns the post ID on success.
You want to automatically add a disclaimer text to every post before it is saved in the database. Which WordPress hook should you use?
Think about which hook lets you change post data just before saving.
The wp_insert_post_data filter allows you to modify post data before it is saved to the database. save_post runs after saving, the_content filters content on display, and init runs too early.