• Hello,

    I am trying to exclude a post from the loop and can’t figure out how to do it.
    Here is my code:

    ‘<?php
    {
    $posts = query_posts($query_string .
    ‘&orderby=title&order=asc&posts_per_page=-1’);
    }
    if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>’

    I’m pretty sure I need to add something to the “query_posts” line, but I don’t know how to make it work.
    Can someone help me add what I need to exclude a post by id or an array of posts by id?
    Any help would be greatly appreciated!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi,

    You just need to use this code to exclude a post from the query post loop:

    <?php

    query_posts(exclude(‘P=5’))

    ?>

    This will exclude the post ID =5 from the query post..

    Thanks,

    Shane G.

    Thread Starter spiralingbob

    (@spiralingbob)

    I tried this, but I must be adding the code in the wrong place. It makes all of my posts disappear!
    I guess I’m a little dumb when it comes to coding like this.
    Is there a specific way it needs to be added? Do I need to somehow include it in this line?

    <?php { $posts = query_posts($query_string .
    '&amp;orderby=title&amp;order=asc&amp;posts_per_page=-1'); }

    Thanks for all the help!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Excluding a post from the loop’ is closed to new replies.