Make WordPress Core

Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#11240 closed defect (bug) (invalid)

Ensure category__in is an array before using it in get_posts

Reported by: johncoswell's profile johncoswell Owned by: ryan's profile ryan
Milestone: Priority: lowest
Severity: minor Version: 2.9
Component: Database Keywords:
Focuses: Cc:


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)

Change History (3)

#1 @johncoswell
14 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Never mind, I see a check's already being done, and it's blowing away non-array values.

#2 @Denis-de-Bernardy
14 years ago

  • Milestone Unassigned deleted

#3 @nacin
13 years ago

(In [16750]) Fix handling of no titles and long titles in internal linking. see #11240.

Note: See TracTickets for help on using tickets.