WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display posts with 'future' status (6 posts)

  1. harrym
    Member
    Posted 4 years ago #

    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?

  2. jvinch
    Member
    Posted 4 years ago #

    As always, Google is your friend!

    Listing Scheduled Posts

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

  3. harrym
    Member
    Posted 4 years ago #

    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;
    }
    
    ?>
  4. gariben
    Member
    Posted 4 years ago #

    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

  5. Andrej Mihajlov
    Member
    Posted 4 years ago #

    Thanks harrym, It's works!

  6. Andrej Mihajlov
    Member
    Posted 4 years ago #

    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;
    }

Topic Closed

This topic has been closed to new replies.

About this Topic