#11240 closed defect (bug) (invalid)
Ensure category__in is an array before using it in get_posts
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | Priority: | lowest | |
| Severity: | minor | Version: | 2.9 |
| Component: | Database | Keywords: | |
| Focuses: | Cc: |
Description
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)
Note: See
TracTickets for help on using
tickets.
Never mind, I see a check's already being done, and it's blowing away non-array values.