post__not_in only excluding first post in array

Posted by fightstarr20 on Stack Overflow See other posts from Stack Overflow or by fightstarr20
Published on 2012-11-16T16:57:17Z Indexed on 2012/11/16 16:59 UTC
Read the original article Hit count: 118

Filed under:
|
|
|

I am using two query_posts loops to firstly display a set of posts with a custom field of '2012' and then the second loop to display everything else excluding the posts it returned in the first...

<?php 
   if( get_query_var('paged') < 2 ) { ?>

<?php
query_posts( array(
    'post_type' => 'project',
    'meta_key' => 'start_date_year',
    'meta_value' => '2012'
    ));
    $ids = array();
?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<p>This is from Loop 1 - <?php the_title(); ?> - <?php the_id(); ?></p>
<?php $ids[] = get_the_ID(); ?>

<?php endwhile; endif; wp_reset_query(); ?>

<?php } ?>

<?php 
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
query_posts( array(
    'post_type' => 'project',
    'post__not_in' => $ids,
    'orderby' => title,
    'order' => ASC,
    'paged' => $paged
    ));
?>

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<p>This is from Loop 2 - <?php the_title(); ?> - <?php the_id(); ?></p>

<?php endwhile; endif; wp_reset_query(); ?>

<?php pagination(); ?>

For some reason the 'post__not_in' => $ids is only excluding the first post ID in the array, I have print_r the array and it does contain all of the post IDs I want to exlcude.

Anyone any ideas why only one ID is being excluded?

© Stack Overflow or respective owner

Related posts about arrays

Related posts about Wordpress