688 posts
  • Bought between 10 and 49 items
  • Exclusive Author
  • Has been a member for 6-7 years
  • Referred between 1 and 9 users
  • Repeatedly Helped protect Envato Marketplaces against copyright violations
  • Sold between 5 000 and 10 000 dollars
  • Uruguay
_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..

2429 posts
  • Has been a member for 4-5 years
  • Exclusive Author
  • Europe
  • Bought between 10 and 49 items
  • Referred between 100 and 199 users
  • Sold between 100 and 1 000 dollars
  • Microlancer Beta Tester
digitalimpact says

Cool, very useful!

Thanks _rg_ :)

by
by
by
by
by
by