Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How can I add to values to the post__not_in function?

For example, I want to exclude $value1 and $value2 from a loop

Any ideas?

Thanks in advance

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This should display 5 posts per page (-1 for all of them on one page), with the post ID's $value1 and $value2 being ignored. Ensure $value1 and $value2 are integers.

$args = array(
    'numberposts' => 5,
    'posts_per_page' => get_option('posts_per_page'),
    'paged' => $paged,
    'post__not_in' => array(
        $value1,
        $value2
    )
);
query_posts($args);

EDIT - With the further informaiton below, and based on the code from that site, try this -

Loop 1 -

<?php
query_posts('showposts=8');
$ids = array();
while(have_posts()) : the_post();
    $ids[] = get_the_ID();
    the_title();
    the_content();
endwhile;
?>

Loop 2 -

<?php
query_posts(array('post__not_in' => $ids));
while(have_posts()) : the_post();
    $ids[] = get_the_ID();
    the_title();
    the_content();
endwhile;
?>

Loop 3 -

<?php
query_posts(array('post__not_in' => $ids));
while(have_posts()) : the_post();
    the_title();
    the_content();
endwhile;
?>

Important notes - Make sure you do not redeclare the $ids array in loop 2 or 3, as this will overwrite the previous array and creat a new, blank one. Also, ensure that you add the IDs from the second loop to $ids so that loop 3 knows what to exclude.

share|improve this answer
    
That didn't seem to help. I'm using a code I found here - wp.smashingmagazine.com/2009/06/10/… It's number 2 in the list and it works fine if I only have 2 loops. But I have 3 and I want the third to exclude post ID's that have appeared in the first 2 –  Dean Elliott Nov 8 '11 at 15:52
    
@DeanElliott - See edits above. –  David Gard Nov 8 '11 at 15:58
    
Perfect. Thanks a lot man, you've saved me a lot of grief –  Dean Elliott Nov 8 '11 at 16:04
    
@DeanElliott - You are welcome. –  David Gard Nov 8 '11 at 16:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.