Show Posts From Multiple Categories
-
I’m trying to figure out the syntax to display posts from multiple categories on a single category page. I’ve done this with query_posts, but I’ve since switched to using pre_get_posts, and can’t figure out the syntax. I’ve got a function in my functions.php file that checks to see if I’m on the desired page, which works, but I can’t figure out the actual query part to grab posts from multiple categories, by name.
Here’s some code I’ve tried:
This code seems to only care about 1 of the categories listed, not both. It also doesn’t take an array, which is desired, as I declare the types for use in earlier code, and would love to avoid manually typing them again.
$query->set('category_name', 'random', 'featured'); //can't take array
This is another way to access the category names, but also didn’t yield the results I was looking for.
$query->query_vars['category_name'] = 'random'; //also doesn't take an array
So my question is, how do I display posts from multiple categories and use pre_get_posts?
- The topic ‘Show Posts From Multiple Categories’ is closed to new replies.