[wp-trac] [WordPress Trac] #11240: Ensure category__in is an array before using it in get_posts

WordPress Trac wp-trac at lists.automattic.com
Mon Nov 23 13:51:31 UTC 2009


#11240: Ensure category__in is an array before using it in get_posts
--------------------------+-------------------------------------------------
 Reporter:  johncoswell   |       Owner:  ryan      
     Type:  defect (bug)  |      Status:  new       
 Priority:  lowest        |   Milestone:  Unassigned
Component:  Database      |     Version:  2.9       
 Severity:  minor         |    Keywords:            
--------------------------+-------------------------------------------------
 If you are directly using `category__in` with `get_posts` and neglect to
 make the input an array, say by passing in an integer value like a
 category ID, `get_posts` fails silently. Ideally, before using
 `category__in`, it should be verified that it is an array, and if it's
 not, it should be wrapped in an array if it's a value type that it
 expects. Then, it should be checked to see if it's an array before the
 rest of the block is executed (wp-includes/query.php, ~line 1802):

 {{{
 if ( !empty($q['category__in']) ) {
   if ( !is_array($q['category__in']) ) {
     if ( is_numeric($q['category__in']) ) {
       $q['category__in'] = array($q['category__in']);
     }
   }
   if ( is_array($q['category__in']) ) {
     ... handle category__in ...
   }
 }
 }}}

 (the `implode` used within will fail strictness checks if it's not an
 array, anyway)

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


More information about the wp-trac mailing list