[wp-trac] [WordPress Trac] #24351: post__not_in is ignored in WP_Query

WordPress Trac noreply at wordpress.org
Thu May 16 05:56:45 UTC 2013


#24351: post__not_in is ignored in WP_Query
--------------------------+-----------------------------
 Reporter:  Dukessa       |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Query         |    Version:  3.5.1
 Severity:  major         |   Keywords:
--------------------------+-----------------------------
 {{{
 $excludeposts = get_option('excluded_blogposts');
 //echo $excludeposts;
 //outputs: 1282,1194,1185

 $excludecat = get_cat_ID('My Cat');
 //echo $excludecat;
 //outputs: 212

 $customquery = null;
 $customquery = new WP_Query( array(
  'post__not_in' => array($excludeposts),
  'category__not_in' => array($excludecat),
  'post_type' => 'post',
  'posts_per_page' => 4
 ));

 //echo $customquery->request;
 /*outputs:
 REQUEST:SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND
 wp_posts.ID NOT IN (1282) AND ( wp_posts.ID NOT IN ( SELECT object_id FROM
 wp_term_relationships WHERE term_taxonomy_id IN (212) ) ) AND
 wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish' OR
 wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY
 wp_posts.post_date DESC LIMIT 0, 4
 */
 }}}

 If I add the IDs manually:
 {{{
 post__not_in' => array(1282,1194,1185)
 }}}
 it works perfectly, but if I pass the variable, it breaks before the first
 comma.

 Anyone with a good explanation/solution? is it a bug?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/24351>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list