• Hi guys,

    A site i am currently working on needs to be able to display “future posts” so that certain events/parties can be shown with ample ‘heads up’ to their userbase.

    Now i have found the support posts and suggestions here in the forums to get WP to show ‘all’ posts in the future via a plugin (by Michael Moncur), this plugin was only designed for users that were logged in.

    So I went about and created my own little plugin that would allow anyone to see posts in future for a certain timeframe ahead (i.e. 30 days)

    My question is, WHY is this plugin only executed for someone that is logged into WP?

    I have just tried this in multiple setups, if i am not logged in the plugin below (even though it’s active) is completely disregarded by WP, I even made the SQL it replaces invalid to see if it would break .. nada.

    I then logged in (with the incorrect SQL replacement still in the active plugin and tada it broke the query.

    I fixed up the preg_replace again and the plugin works absolutely find as long as i am logged in. I can change the days in the future it should grab posts up to, to anything i please with the result instantly showing
    up in any section of the site.

    Now I do know of the ‘hack’ for classes.php which lets me fix this problem for any user, logged in or not but i’d much rather do this the ‘proper’ way so that i can upgrade WP in the future without breaking core files.

    If anyone knows WHY this plugin is only executed when you’re logged in OR how to fix this ‘problem’, PLEASE let me know.

    function x_futureposts_plugin($content){

    //amount of days in the future post will be retrieved for;
    //i.e. 30 to grab everything from now +30 days ahead
    $daysAhead = 30;

    //don't edit below (unless you know what you're doing
    $date_daysAhead = gmdate('Y-m-d H:i:59',mktime(0, 0, 0, gmdate("m"), gmdate("d")+$daysAhead, gmdate("Y")));

    $content = preg_replace("/AND post_date_gmt <= '.+')/", "AND post_date_gmt <= '$date_daysAhead'", $content);
    return $content;
    }
    add_filter('posts_where', 'x_futureposts_plugin');

    Thanks,
    Ragnar

Viewing 3 replies - 1 through 3 (of 3 total)
  • “Now i have found the support posts and suggestions here in the forums to get WP to show ‘all’ posts in the future via a plugin (by Michael Moncur), this plugin was only designed for users that were logged in….”

    This doesn’t help with your plugin, but according to the website that hosts the VIEW FUTURE POSTS plugin, you can modify two variables:

    $future_min_level—the minimum user level required to view future posts. The default is 10 (administrators). Set this to zero to allow everyone (even anonymous users) to view future posts.
    $future_single_only—if set to true (default), future posts are available from their unique permalink only. If set to false, future posts appear on the categories, archives, and the home page.

    sorry, double-post

    Hi, I stumbled on this tread today try to accomplish the task of displaying future posts to ALL visitors of my site. I tried the solution offered by holly2000, and while it may work with WP v1.5 (the version that this plugin was created for), it failed for my current install of 2.1.3. I did however accomplish what I set out to do by using the following code:

    function wp_future_posts_plugin_mod($content) {
    	$content = preg_replace("/AND post_date_gmt <= '.+'/", "AND 1", $content);
    	return $content;
    }
    add_filter('posts_where', 'wp_future_posts_plugin_mod');

    I hope that someone finds this helpful.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugins only working for logged in users ?’ is closed to new replies.