Making scheduled posts in WordPress public so they can be scheduled / scraped on social media

The basics of scheduling in WordPress are quite simple: If you give a WordPress post a published date set in the future, it’ll remain “hidden” on your website until that date and time arrives. It’ll then appear, right on time, at the top of your list of public posts.

But here’s an interesting problem: Social media is now a major driver (maybe the driver) of traffic to digital media websites. When you schedule your post in WordPress, you’ll also naturally want to schedule that post to appear on Facebook and Twitter – but that would require the WordPress post to be public, which in its “future” post status isn’t yet.

// Allow site visitors to view posts in the "future" post status.
function show_future_posts( $posts ) {
   global $wp_query, $wpdb;

   if ( is_single() && $wp_query->post_count == 0 ) {
      $posts = $wpdb->get_results($wp_query->request);
   }
 
   return $posts;
}
add_filter('the_posts', 'show_future_posts');

Reference:

Leave a Reply

Your email address will not be published. Required fields are marked *