0

I am using post__not_in to remove pages from a query but it's ignoring anything more than 2 items

My code:

$selected_check = array();
  $checks = new WP_Query( 'post_type=page&orderby=menu_order&order=ASC&posts_per_page=-1');
  while($checks->have_posts()){
   $checks->the_post();
   global $post;
   $this_check = get_post_meta($post->ID, '_cmb_hide_home', true);
   if($this_check == 'on'){
    $selected_check[] = $post->ID;
   }
  } 
  wp_reset_postdata();

  $new_check = implode(", ", $selected_check);

  $query1 = new WP_Query(array(
  'post_type' => 'page',
  'orderby' => 'menu_order',
  'order' => 'ASC',
  'posts_per_page' => '-1',
  'post__not_in' => array($new_check)
 ));

My $new_checks array is currently 51, 76, 10, 21 but it's only working on the first 2 items

Is there something I am missing in my code?

1 Answer 1

1

post__not_in should be an array of post IDs - remove the implode line and just pass $selected_check as the argument value instead of array( $new_check ).

1
  • Cheers, I was trying to be too clever for my own good, I am not sure why but I thought I had to use the implode to add the commas to make the array work :) Aug 27, 2014 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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