WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Display future post on single pageview? (9 posts)

  1. Jacorre
    Member
    Posted 3 years ago #

    I'm able to display future posts using post_status=future within a query posts loop. I'm also able to display future posts in my RSS feed. The problem is that if someone clicks on the future post in the RSS feed, it can't bring them to the post because it's not technically posted yet.

    Is there any way to change the single.php template file to allow for viewing future posts?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Have you tried adding a similar custom query to single.php?

  3. Jacorre
    Member
    Posted 3 years ago #

    I have tried that and it ends up displaying all posts instead of the one I clicked on.

  4. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Well, you'd obviously need to modify the query so that it was only calling a single post...

  5. Jacorre
    Member
    Posted 3 years ago #

    And how would one do that?

    On the single.php template file, I try placing the query_post("post_status=publish,future") before the loop because I would still want to published posts to be viewed as well. But when I click on a post from an archive page, it ends up giving me all the posts instead of just the one I clicked on.

  6. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    global $query_string;
    query_posts( $query_string . 'post_status' => array('publish','future') );
  7. Jacorre
    Member
    Posted 3 years ago #

    Unless I'm doing something wrong, that's not working. I used the following on my single.php template file:

    <?php global $query_string;
    query_posts( $query_string . 'post_status' => array('publish','future') );
    if (have_posts()) : while (have_posts()) : the_post(); ?>
  8. Jacorre
    Member
    Posted 3 years ago #

    I found a solution. I added the following to my functions.php file:

    /* Show future posts */
    function show_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', 'show_future_posts');

    Thanks for your help though!

  9. pettedemon
    Member
    Posted 2 years ago #

    But if I want apply this filter only for one category??

Topic Closed

This topic has been closed to new replies.

About this Topic