688 posts
  • Has been part of the Envato Community for over 7 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
+2 more
digitalimpact says

Cool, very useful!

Thanks _rg_ :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by