0
0
Wordpressframework~10 mins

Creating and editing posts in Wordpress - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A'My First Post'
B'Sample Post'
C'Hello World'
D'New Post'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around the title string
Using a variable name instead of a string
2fill in blank
medium

Complete 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'
A'This is the updated content.'
BThis is the updated content.
C42
D'post_content'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around the content string
Passing a number instead of a string
3fill in blank
hard

Fix 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'
A42
B$post_id
C'42'
Dpost_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the post ID
Using a variable name without defining it
4fill in blank
hard

Fill 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'
A'Draft Post'
B'publish'
C'draft'
D'New Post'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'draft' for status
Not using quotes around strings
5fill in blank
hard

Fill 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'
A'Updated Title'
B'New content for the post.'
C'private'
D'publish'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'private' for status
Forgetting quotes around strings