Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a new post with a title in WordPress.
Wordpress
<?php
$post_id = wp_insert_post(array(
'post_title' => [1],
'post_status' => 'publish',
'post_type' => 'post'
));
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the title string
Using a variable name instead of a string
✗ Incorrect
The 'post_title' key needs a string value for the post's title. 'Hello World' is a common example title.
2fill in blank
mediumComplete the code to update the content of an existing post in WordPress.
Wordpress
<?php
$post_update = array(
'ID' => 42,
'post_content' => [1]
);
wp_update_post($post_update);
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the content string
Passing a number instead of a string
✗ Incorrect
The 'post_content' value must be a string with quotes around it to update the post content.
3fill in blank
hardFix the error in the code to properly delete a post by ID in WordPress.
Wordpress
<?php
$result = wp_delete_post([1], true);
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the post ID
Using a variable name without defining it
✗ Incorrect
The post ID must be an integer without quotes. Using 42 as a number is correct.
4fill in blank
hardFill both blanks to create a post with a title and set its status to draft.
Wordpress
<?php
$post_data = array(
'post_title' => [1],
'post_status' => [2],
'post_type' => 'post'
);
$post_id = wp_insert_post($post_data);
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'draft' for status
Not using quotes around strings
✗ Incorrect
The title should be a string like 'Draft Post'. The status must be 'draft' to save as draft.
5fill in blank
hardFill all three blanks to update a post's title, content, and set it to private.
Wordpress
<?php
$post_update = array(
'ID' => 101,
'post_title' => [1],
'post_content' => [2],
'post_status' => [3]
);
wp_update_post($post_update);
?> Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'private' for status
Forgetting quotes around strings
✗ Incorrect
The title and content must be strings in quotes. The status 'private' makes the post visible only to authorized users.