tags:

views:

42

answers:

3

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?

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

+2  A: 

Here's the relevant info from the docs:

'post__not_in' => array(6,2,8) - exclusion, lets you specify the post IDs NOT to retrieve

UncleZeiv
+2  A: 

It's in the Codex: http://codex.wordpress.org/Function_Reference/query_posts

use the post__not_in, something like: query_posts(array('post__not_in'=>'1,2,3'))

robertbasic
A: 

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/

jcady
This is not good because you have to pull more data than you want to display. WordPress has a pretty high overhead as it is, don't make it work harder than it has to to get the job you want done.
Gipetto