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!