Following on from my recent post about filtering WordPress search results by category, here's how to show posts from multiple WordPress categories on one search results page.
To start the example, let's take one of the categories on this site:
(in case you were wondering, I've used the Yoast SEO plugin to remove the /categories/ prefix from my category page URLs, but that's not important here.)
Alternatively I can use the category ID as a URL parameter to get the same result:
You'll notice this URL automatically redirects to the first one.
Now it's actually possible to include two (or more) category IDs in the URL, comma separated like this:
This search results page will show posts from both category 41 (Domains and Hosting) AND category 31 (Social Media). Neat, huh!
Incidentally, the order of the IDs doesn't determine the order of the posts - the posts are listed, by default, in date order from newest to oldest. However, the first ID given determines the title of the page (both meta title and post title).