0
0
Wordpressframework~10 mins

Post scheduling and status in Wordpress - Interactive Code Practice

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

Complete the code to schedule a post to publish in the future.

Wordpress
<?php
$post = array(
  'post_title'    => 'My Scheduled Post',
  'post_content'  => 'Content here',
  'post_status'   => '[1]',
  'post_author'   => 1,
  'post_date'     => '2024-12-31 10:00:00'
);
wp_insert_post($post);
?>
Drag options to blanks, or click blank then click option'
Adraft
Bpublish
Cfuture
Dpending
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' will publish the post immediately.
Using 'draft' will save the post as a draft, not schedule it.
2fill in blank
medium

Complete the code to check if a post is scheduled.

Wordpress
<?php
$post = get_post($post_id);
if ($post->post_status === '[1]') {
  echo 'This post is scheduled.';
}
?>
Drag options to blanks, or click blank then click option'
Aprivate
Bpublish
Cdraft
Dfuture
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'publish' will not detect scheduled posts.
Using 'draft' will only find unscheduled drafts.
3fill in blank
hard

Fix the error in the code to update a post's status to scheduled.

Wordpress
<?php
$post_update = array(
  'ID'          => $post_id,
  'post_status' => '[1]',
  'post_date'   => '2025-01-01 08:00:00'
);
wp_update_post($post_update);
?>
Drag options to blanks, or click blank then click option'
Apublish
Bfuture
Cdraft
Dprivate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' will publish the post immediately.
Not setting the status to 'future' will not schedule the post.
4fill in blank
hard

Fill both blanks to create a query that fetches only scheduled posts.

Wordpress
<?php
$args = array(
  'post_status' => '[1]',
  'posts_per_page' => [2]
);
$query = new WP_Query($args);
?>
Drag options to blanks, or click blank then click option'
Afuture
Bpublish
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' will fetch published posts, not scheduled.
Setting posts_per_page too low or too high without reason.
5fill in blank
hard

Fill all three blanks to create a function that schedules a post with a custom status check.

Wordpress
<?php
function schedule_custom_post($post_id, $date) {
  $post_data = array(
    'ID' => $post_id,
    'post_status' => '[1]',
    'post_date' => $date
  );
  $result = wp_update_post($post_data);
  if ($result && get_post_status($post_id) === '[2]') {
    return '[3]';
  }
  return 'Failed to schedule';
}
?>
Drag options to blanks, or click blank then click option'
Afuture
Bpublish
CScheduled successfully
Ddraft
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'publish' instead of 'future' for scheduling.
Not checking the correct post status after update.