[wp-trac] [WordPress Trac] #12212: post__in can't manage empty array properly

WordPress Trac wp-trac at lists.automattic.com
Mon Feb 15 14:20:37 UTC 2010


#12212: post__in can't manage empty array properly
--------------------------+-------------------------------------------------
 Reporter:  lifeless85    |       Owner:  ryan          
     Type:  defect (bug)  |      Status:  new           
 Priority:  normal        |   Milestone:  Future Release
Component:  Query         |     Version:  2.9.1         
 Severity:  normal        |    Keywords:  post__in      
--------------------------+-------------------------------------------------

Comment(by lifeless85):

 i've managed to write a simple and in my opinion acceptable solution:
 changing the {{{'''function''' fill_query_vars()}}} in the following way:
 {{{
 foreach ( $array_keys as $key ) {
         if ( !isset($array[$key])) {
                 if( $key == 'post__in' ){ continue; }
                 $array[$key] = array();
         }
 }
 }}}
 ''Notice that we should also change {{{category__in, tag__in,
 tag_slug__in}}}''
 And managing the new meaning of empty array inside of {{{'''function'''
 &get_posts()}}} like this :
 {{{
   elseif ( is_array($q['post__in']) && empty($q['post__in']) ) {
         $where = " AND {$wpdb->posts}.ID = NULL";
         $this->set_404();
 } elseif ( $q['post__in'] ) {
         $post__in = implode(',', array_map( 'absint', $q['post__in'] ));
         $where .= " AND {$wpdb->posts}.ID IN ($post__in)";
 }
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/12212#comment:12>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list