Resources     Blog  

  1. Home
  2. WordPress Tutorials
  3. How to Show Scheduled Posts in WordPress

How to Show Scheduled Posts in WordPress

Are you looking for a way to show scheduled content to your visitors? By default, WordPress will only allow author, editor, and administrator user roles to see your scheduled content. All other user roles, unless changed, cannot see them, including visitors. This can be an issue for websites that want to show visitors what content to look forward too.

There are multiple ways to deal with this problem depending on what you want to do. One of the best methods is to set up an events calendar on your website or Facebook Events that will list when your content is coming out. This method may not work for every website, so instead, using code can be just as good. Today, I will demonstrate how to show scheduled posts in WordPress with simple code.

Why List Upcoming Posts in WordPress

It is natural for visitors who enjoy your content to wonder when the next piece of content will be released. This is true for all forms of entertainment, movies, video games, books, ect., not just websites. Listing your future content is a good way to keep loyal visitors informed and get them excited for the release. In WordPress, upcoming posts are known as “scheduled” and will become “public” posts once the publishing date and time occur.

Consider Facebook Events

To be a successful website in today’s world, you need to have social media pages to promote your content. It is normal to have Twitter accounts that run on autopilot to alert your followers when a new post goes live. Facebook is by far the world’s most popular social media platform. You can definitely just make posts on Facebook alerting your followers when a new post goes live, but Facebook Events is a better option.

Facebook Events is a calendar based system. You can use it to display what your upcoming content releases are in a month. For example, let’s say you release a new post every Friday. You can then set up your Facebook Events to display the title for your new release so your followers can see what the future holds. It’s a great way to connect your content release schedule with your social media pages.

How to Show Scheduled Posts in WordPress

Today, I will demonstrate how to show scheduled posts in WordPress with simple code. While there may be a few plugins that can do this, many of the ones I have looked at have not been updated in months. While these can still work perfectly fine, it is better to avoid them because they can become a security vulnerability. Instead, manually creating a shortcode to use with a widget that can show scheduled posts in WordPress is the safer way.

You will not need any prior coding knowledge since you can just copy and paste the code as it is. However, before editing any code, you should take this time to create a backup of your website. This will ensure that if a mistake is made, you can use the backup to revert your website to before the mistake was made.

Creating a Widget

Let’s start by logging into the cPanel and clicking on the File Manager option. The File Manager will allow you to access all of the files related to your website.

Click on the File Manager option.

You need to locate your theme’s functions.php file. Click on the public_html directory, then click on the wp-content folder. Inside of this folder, you will find all of the content related to your website. Click on the themes folder and enter the folder of the theme you are currently using. Finally, right-click on the functions.php file and select the Edit option.

Select the "Edit" option.

A pop-up window will show up. This box will warn you to create a backup of your files before editing anything. This will ensure that you can revert your website back to when it was working if something goes wrong. Click on the “Edit” button. A new tab will open containing all of the code from the file.

Click on the "Edit" button.

Now that you are in your functions.php file, simply copy and paste the following code:

function Display_Scheduled_Posts() {
// The query to locate scheduled posts on your website
$the_query = new WP_Query(array(
‘post_status’ => ‘future’,
‘posts_per_page’ => 3,
‘orderby’ => ‘date’,
‘order’ => ‘ASC’
));

// The following If statement will display all scheduled posts
if ( $the_query->have_posts() ) {
echo ‘<ul>’;
while ( $the_query->have_posts() ) {
$the_query->the_post();
$output .= ‘<li>’ . get_the_title() .’ (‘. get_the_time(‘d-M-Y’) . ‘)</li>’;
}
echo ‘</ul>’;

} else {
// Message when no scheduled posts are found
$output .= ‘<p>Sorry! We are still working on new content.</p>’;
}

// Reset post data
wp_reset_postdata();

// Return output

return $output;
}
// Add shortcode
add_shortcode(‘scheduled_posts’, ‘Display_Scheduled_Posts’);
// Allow shortcode execution inside text widgets
add_filter(‘widget_text’, ‘do_shortcode’);

Once you have inserted the code into the functions.php file, click on the “Save Changes” button to finish.

Click on the "Save Changes" button.

The Shortcode

You have just created the following shortcode:

[scheduled_posts]

This can be used on any page, post, or text widget on your website. I recommend the sidebar if you have room because everyone will be able to see your upcoming releases regardless of where they are on the website.

Once the shortcode has been placed, you can check your live website to see the results.

Congratulations, you have successfully learned how to show scheduled posts in WordPress. You can remove it at any time by deleting the shortcode and deleting the actual function from your functions.php file.

Keep Visitors Informed

While you may get a lot of your clicks from search engines like Google, keeping your loyal visitors informed about new content is the best way to guarantee views on your website. Keeping your visitors informed and aware of your content schedule shows them that your website is trustworthy and produces content regularly. Many websites that do not produce content regularly usually have a hard time getting returning visitors unless their content is really good.

How much scheduled content do you have to show? How much content do you release in a month?

Author: Robert Giaquinto

Robert has been writing tutorials about WordPress and other CMS for over 3 years since joining the GreenGeeks marketing team. Thanks to this, he has had the opportunity to research and master several areas of WordPress including plugin usage, SEO, website design, and social media integration. When he is not creating content for WordPress, Robert is digging up new content ideas for environmental pieces. These range from the pollution in our air to the danger’s wildlife face. And with a bachelor’s degree in electrical engineering, he is always eager to discuss the way our technologies are affecting the environment, especially when it comes to solar energy.

Was this article helpful?

Related Articles

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.