Show timed posts that are not yet live – Show future posts

Last update: 15.09.2022.

If you are using pre-timed posts as a way to display future programs, you may have a problem that they don’t show up because they haven’t reached their dates yet. The following code snippet provides a solution.

What is the point of a future post? In this case, if you time them to the start date of a program, they will only be visible as long as they are current.

// functions.php
<?php add_filter('the_posts', 'show_future_posts'); 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; } ?>

// loop <?php $temp = $wp_query; $wp_query= null; $wp_query = new WP_Query(); $wp_query->query('showposts=10&category_name=programs&post_status=future&sort_column=post_date&order=ASC');?> <?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?> <?php endwhile;?> <?php $wp_query = null; $wp_query = $temp;?>

Copy to Clipboard

Related posts

Got a question? Is something not working? Write and I'll answer!

Leave a Reply

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