How to show posts that are in BOTH of two categories on a WordPress search results page

21 September 2019

Previously I've written about how to show posts from more than one WordPress category on one search page (ie posts from category A and posts from category B). But what if you want to show only posts that are in BOTH category A and category B? That's possible too, though it's perhaps done a slightly counter-intuitive way.

Let's take two of the categories on this site, 'web development' and 'online advertising':

It is also possible to use the category IDs as URL parameters to get the same results (actually these latter URLs just redirect to the former ones):

Brilliantly, you can combine these two approaches to see only posts that are in both the 'web development' and 'online advertising' categories.

The two pages list the same posts but are not completely the same themselves.

The first is the 'web development' category page filtered to show only posts that are also in 'online advertising', so it has the 'web development' page furniture (for example the intro text at the top of the page).

Conversely, the second is the 'online advertising' page filtered to only show posts that are also in 'web development', so has the 'online advertising' page furniture.

Looking online, other people have posted different approaches to the same problem (for example using a URL parameter with the format ?cat=firstcat+secondcat). None of these seem to work for me - that is not to say they would not work for you or your site.

Notify of
Inline Feedbacks
View all comments
James Clark
Hi! I'm James Clark and this is my website. I publish all my guides completely free, so if you find them useful then please:
What do you think? Leave a commentx
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram