Majo0od Majo0od -4 years ago 101
PHP Question

Exclude post from query_posts() wordpress

I'm trying to exclude a post from loop like:

query_posts("posts_per_page=5&cat=1, -15&post__not_in = 1");

isn't working. Do I have the command all wrong?

Answer Source

The reason it isn't working is because post__not_in expects an array which you can use when you are using the WP_Query class.

Try using WP_Query instead:

$args = array('posts_per_page' => 5,
              'cat'            => '1,-15',
              'post__not_in'   => array(1),

$posts = new WP_Query( $args );

while ($posts->have_posts()) {
    echo the_title() . '<br />';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download