• So I have showcase kind of thing at the top of my homepage in which I put the most recent post that has the category “Featured Post.”

    To get the post into the “showcase” div, I used a wp_query:

    <div id="showcase">
    <?php $featuredpost = new WP_Query('cat=16&posts_per_page=1'); ?>
    
    <?php while($featuredpost->have_posts()) : $featuredpost->the_post(); ?>
    <div id="featured" <?php post_class(); ?>>
    		//LOOP STUFF SNIPPED OUT FOR BREVITY
    </div><!-- #featured -->
    <?php endwhile; ?>
    </div><!-- #showcase -->

    Underneath the showcase comes the regular content section — via the regular Loop. But I want to exclude the $featuredpost from that loop so that the showcase post is not duplicated in the regular blog listing.

    Was playing with this:

    <?php query_posts(array('post__not_in' => $featuredpost)); ?>

    just above the main loop. But that gave me no posts at all from the main loop. I can’t find any documentation on post__not_in in the codex.

    Can anybody help me with this?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter bob.passaro

    (@bobpassaro)

    I’m thinking the problem here is the variable. I probably need at post ID??

    I think you are right. Just above your ‘//LOOP STUFF’ line, save the ID into a variable:

    $featured_id = $post->ID;
          //LOOP STUFF ...

    Then use the $featured_id for the post__not_in value.

    Thread Starter bob.passaro

    (@bobpassaro)

    Thanks. But I’m afraid, that’s not working either.

    On second though, I think I’m not using post__not_in properly.

    Anybody know a resource on using post__not_in?

    Here is the Codex Function Reference that has the info.

    post__not_in takes an array even if there is only one element, like this:

    ?php query_posts(array('post__not_in' => array($featured_id) )); ?>
    Thread Starter bob.passaro

    (@bobpassaro)

    oh, thanks.

    Don’t know why I didn’t find that earlier. I’ll play with it some more.

    Thread Starter bob.passaro

    (@bobpassaro)

    Hey! Victory on a Friday afternoon! That worked.

    Needed this:

    <?php query_posts(array('post__not_in' => array($featuredid))); ?>

    instead of this:

    <?php query_posts(array('post__not_in' => $featuredpost)); ?>

    Thanks vtxyzzy! Now I can feel better about heading off for happy hour 🙂

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Two loops and excluding one post’ is closed to new replies.