688 posts
  • Has been part of the Envato Community for over 6 years
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
+3 more
_rg_ says

I came across this thing, to show on the entire site the future posts, the content site needs that feature, to post future events, but i don´t want to use any plugin, just the same posts but in future, and visible for users on the entire site without the need to create customs querys for each template.

So, i decided to create a filter, but, i couldn´t find any information on how to do it, so i started to play some things….

And i build this two simple filters:

This one adds an arrgument to the global query, so you will see future posts on any loop:
function eventsFilter($query) {
    $query->set('post_status','publish,future');
    return $query;
}
add_filter('pre_get_posts','eventsFilter');
This one let not logged visitor to see the future on single.php:
function signle_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', 'signle_future_posts');

Put that on functions.php and you have a new query on the entire site that will show also the future posts.

I need to check if works for the native calendar widget, but….

Once i discover this and taking in consideration the amount of comments all over the net asking how to do something like this, i can´t bellive was so easy.

I did this just 5 min. ago and i decided to share-right-now.

:)

edited: sorry i created the thread on wrong area..

2468 posts
  • Has been part of the Envato Community for over 5 years
  • Has sold $100+ on Envato Market
  • Has referred 100+ members
  • Has been a beta tester for an Envato feature
+3 more
digitalimpact says

Cool, very useful!

Thanks _rg_ :)

by
by
by
by
by
by