excluding posts in WordPress

I wondered how I could exclude posts in WordPress.
E.g. I have a string

$exclude_ids (= "4,5,6") or (="-4,-5,-6")

and I would like to prevent these posts from showing up. How would I do that?

Read More

I already tried:

query_posts('p=' . $exclude_ids);

but that didn’t really work out and I didn’t really find any information regarding this topic on google.

Cheers

Related posts

Leave a Reply

3 comments

  1. The ideal solution would be to create a category, add those posts to it, then exclude the category. But if you really want to single out posts, it could be done as follows:

    <?php if (have_posts()) : 
        while (have_posts()) : the_post();
        if ($post->ID == '179' || $post->ID == '180' || $post->ID == '181') continue;?>
    <?php the_content();?>
    <?php endwhile;endif;?>
    

    Just use that if statement in your Loop. The continue will skip over that iteration for any of the listed posts.

    Source: http://www.sandboxdev.com/blog/wordpress/180/exclude-single-post/