Forums

Exclude single post from query post (3 posts)

  1. circleatseven
    Member
    Posted 9 months ago #

    How would exclude 1 post using the post id (321) in this code?

    <?php query_posts("category_name=event-catering&showposts=100");
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    I've tried adding &p=-321 like this:

    <?php query_posts("category_name=event-catering&showposts=100&p=-321");
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    .. but instead of excluding post id 321, it shows ONLY that post and excludes everything in the "event-catering" category..?

    Thoughts?!

  2. alchymyth
    The Sweeper
    Posted 9 months ago #

    try:

    <?php query_posts(array('category_name' => 'event-catering', 'posts_per_page' => 100, 'post__not_in' => array(321)));
    	if ( have_posts() ) : while ( have_posts() ) : the_post();
    ?>

    http://codex.wordpress.org/Class_Reference/WP_Query#Post_.26_Page_Parameters

  3. circleatseven
    Member
    Posted 9 months ago #

    You rock! THANK YOU SO MUCH!!!!! Worked perfectly!

Reply

You must log in to post.

About this Topic