How to show posts from multiple WordPress categories on one search results page

1 August 2019

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:

https://www.technicallyproduct.co.uk/domains-hosting/

(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:

https://www.technicallyproduct.co.uk/?cat=41

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:

https://www.technicallyproduct.co.uk/?cat=41,31

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).

Leave a Reply

Your email address will not be published. Required fields are marked *

Copyright © James Clark
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram