• I’m using this code in my functions.php file, but it displays all future posts, no matter the categoru:

    // Show Single Future Posts
    add_filter('the_posts', '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;
    }

    so I added && in_category(‘8’) after is_single(), but that doesn’t work.

    // Show Single Future Posts
    add_filter('the_posts', 'show_future_posts');
    function show_future_posts($posts){
       global $wp_query, $wpdb;
       if(is_single() && in_category('8') && $wp_query->post_count ==0){
          $posts = $wpdb->get_results($wp_query->request);
       }
       return $posts;
    }

    Can someone please tell me how to fix this?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try something like this:

    $cat_id = 8;
    $postlimit = -1;
    $now = current_time('mysql');
    $future_posts = $wpdb->get_results("SELECT * FROM $wpdb->posts, $wpdb->post2cat WHERE category_id = '$cat_id' AND post_id = ID AND post_date > '$now' LIMIT $postlimit");
    return $future_posts;

    Thread Starter Jack

    (@moxie)

    Should that code be in functions.php or in single.php?

    Thread Starter Jack

    (@moxie)

    Single.php should ofcourse still be used for all single posts, but I have two categories that can contain future posts: News and Agenda.

    Future posts from News should never be visible until they are published, but future posts from Agenda should be visible for visitors.

    Should that code be in functions.php or in single.php?

    Depends:
    – If you are creating your own single.php; then you may place it in that file.
    – If you are using a child theme, place it in the functions.php file.
    – If you are modifying core theme files.. shame on you! Any changes you make will be over-written the next time you update your theme.

    Future posts from News should never be visible until they are published, but future posts from Agenda should be visible for visitors.

    This is new information to me.. and not mentioned anywhere in your original post. That will require a little more extensive code.

    Does the original snipped above work in it’s capacity?

    Thread Starter Jack

    (@moxie)

    I’m sorry I was not completely clear in my first post.

    Yes, the original snippet works. I can’t test it again right now because I made a stupid mistake and now the site is down (and waiting for someone to give me the FTP settings…), but it worked before.

    No worries.

    Okay.. I have to step out for a bit. But, I can take another look at this later tonight, if no one else posts back by then.

    Thread Starter Jack

    (@moxie)

    Ok, that snippet works, defenitely. The only problem now is that when a search is done, the posts from the Agenda category don’t appear, while they should.

    It’s more complicated then I thought. I also asked about this in the forum of the plugin The Future is Now, because if that plugin would allow for categories to be included or excluded, the problem would be solved.

    http://wordpress.org/support/plugin/the-future-is-now

    Well, we are only working with one category (8) in our code. I’m not sure which one this is (News or Agenda). But if you find the ID of the other category.. we can begin to use both; and run “if” clauses on each.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display future single post from specific category’ is closed to new replies.