How do I include multiple category IDs in WordPress query?
-
I’m using category__in to include multiple category IDs but when I try to put the comma-separated list into an array it doesn’t work. This is what I have tried:
$included_categories = array(2,21,27,29); $args['category__in'] = $included_categories;
Which results in this query:
array ( 'category__in' => array ( 0 => 2, 1 => 21, 2 => 27, 3 => 29, ) )
But as per the WordPress Codex the correct syntax should be:
array ( 'category__in' => array( 2,21,27,29 ) )
I can’t figure out how to create an array of purely comma-separated IDs without having the key/value pairs. Note: I can’t just write out the query as instructed by the Codex because I’m building it out as shown in my code above.
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘How do I include multiple category IDs in WordPress query?’ is closed to new replies.