I'm posting this hoping to learn a bit about filters and $wp_query.

I researched how to

  • show a single post
  • with a published date in the future
  • when not logged in

and found out that you can do this using this function, which I found here:

add_filter('the_posts', 'show_all_future_posts');

function show_all_future_posts($posts){
        global $wp_query, $wpdb;
       if(is_single() && $wp_query->post_count == 0)
      $posts = $wpdb->get_results($wp_query->request);
return $posts;

My question:

Why would $wp_query->post_count == 0 need to be part of the conditional? It seems to me that on a single page the $wp_query would return a post count of 1.

Is $wp_query->post_count 0 when the query returns a post with the future published status?

This is clearly not an emergency, but if anyone could explain why that filter ends up showing posts with the future publish status, I'd be grateful!

1 Answer 1


I think the answer is:

when you'r in single page/post/cpt view ( you'r checking it with is_single() ) you always should have $wp_query->post_count equal 1, but if it is future post/page/cpt than it will result to 0 ( becouse there are function/actions applyed to check if it is future post )

and $posts = $wpdb->get_results($wp_query->request); that how you'r telling not to apply these functions/actions wich checks for future posts/pages/cpt


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.