Support » Plugins and Hacks » Display posts with ‘future’ status

  • Resolved harrym

    (@harrym)


    Hi there,

    I (probably unusually) want to display single posts with a status of future, but only if they’re in a specific category.

    So far as I can see, get_posts just scrubs the posts array of anything unpublished if the user isn’t logged on (which they won’t be). See wp-includes/query.php:2288.

    I thought about doing something really hacky with is_user_logged_in, along the lines of:

    if(is_single() && is_in_my_category())
    {
       return true;
    }
    else
    {
       [normal code from pluggables]
    }

    but that creates its own problems and is generally pretty horrid anyway.

    Can anyone think of a nice way to do it?

Viewing 5 replies - 1 through 5 (of 5 total)
  • As always, Google is your friend!

    Listing Scheduled Posts

    All you need to do is add the category to your query.

    Listing the posts works fine. I’m talking about dispaying them in single.php.

    I just figured it out though — should have thought for a bit longer 🙂

    <?php
    
    add_filter('the_posts', 'plug_the_posts');
    
    function plug_the_posts($posts)
    {
       global $wp_query, $wpdb;
    
       if(is_single() && $wp_query->post_count == 0)
       {
          $the_posts = $wpdb->get_results($wp_query->request);
    
          if(post_is_in_descendant_category('future', $the_posts[0]))
          {
             $posts = $the_posts;
          }
       }
    
       return $posts;
    }
    
    ?>

    Hi Harrym…

    I have the same problem.. My site is basically a calendar event site which list current “events” and future events.

    I would like the future events to be viewable.

    Where do you insert the codes to make “scheduled post” viewable.

    http://www.tokyoevents.com

    Thanks,
    Mike

    Thanks harrym, It’s works!

    gariben, just write a plugin and put it into wp-content/plugins directory and activate it.

    This plugin will show any future post from any category (The harrym’s code shows the posts only from ‘future’ category):

    /*
     * Plugin Name: Show All Future Posts
     * Author URI: http://mysite.com
     * Plugin URI: http://mysite.com/myplugin
     * Description: Make all future posts visible
     * Author: Me
     * Version: 1.0
     */
    
    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;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display posts with ‘future’ status’ is closed to new replies.