0
0
Wordpressframework~20 mins

Creating and editing posts in Wordpress - Practice Exercises

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
WordPress Post Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you save a post with the status 'draft' in WordPress?

In WordPress, when you create a new post and save it with the status set to 'draft', what is the expected behavior?

AThe post is immediately visible on the website homepage.
BThe post is deleted automatically after saving.
CThe post is published but marked as private.
DThe post is saved but not visible to the public until published.
Attempts:
2 left
💡 Hint

Think about what 'draft' means in everyday writing before sharing.

📝 Syntax
intermediate
2:00remaining
Which WordPress function correctly creates a new post programmatically?

Choose the correct PHP function call to create a new post in WordPress with the title 'Hello World' and content 'Welcome to my blog'.

Acreate_post(title='Hello World', content='Welcome to my blog');
Binsert_post('Hello World', 'Welcome to my blog');
Cwp_insert_post(['post_title' => 'Hello World', 'post_content' => 'Welcome to my blog', 'post_status' => 'publish']);
Dadd_post(['title' => 'Hello World', 'content' => 'Welcome to my blog']);
Attempts:
2 left
💡 Hint

Look for the official WordPress function that inserts posts.

🔧 Debug
advanced
2:00remaining
Does this code successfully update the post content?

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);
Wordpress
$post_id = 42;
$post_data = ['ID' => $post_id, 'post_content' => 'New content here'];
wp_insert_post($post_data);
AThe code works correctly and updates the post content.
BThe function wp_insert_post cannot update posts, only create new ones.
CThe 'ID' key must be lowercase 'id' to update a post.
DThe post status is missing, so WordPress ignores the update.
Attempts:
2 left
💡 Hint

Recall that wp_insert_post can update existing posts if the 'ID' is provided and the post exists.

state_output
advanced
2:00remaining
What does wp_update_post return with an invalid post ID?

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?

Wordpress
$result = wp_update_post(['ID' => 999999, 'post_content' => 'Updated content']);
AA PHP warning error is thrown.
B0 (zero), indicating failure to update.
Cnull, because the function returns nothing.
DThe post ID 999999, indicating success.
Attempts:
2 left
💡 Hint

Check the WordPress documentation for wp_update_post return values on failure.

🧠 Conceptual
expert
2:00remaining
Which WordPress hook is best to modify post content before saving it?

You want to automatically add a disclaimer text to every post before it is saved in the database. Which WordPress hook should you use?

Awp_insert_post_data
Bthe_content
Csave_post
Dinit
Attempts:
2 left
💡 Hint

Think about which hook lets you change post data just before saving.