On one of the websites I am administrating, posts are assigned two kinds of categories:
- the age of children
- for boys or for girls
In the navigation menu, you need to be able to select menu items corresponding to the following types of criteria:
- Display all posts for boys or all posts for girls
- Display all posts for children in a specific age category
- Display all posts for boys in a specific age category or for girls in a specific age category
The first two requirements are easy. You just need to add the corresponding category archives to the menu. For the last one, there is no way to select a combination of categories in the WordPress menu builder.
So you need to add links to the menu and point to the results of a query for a combination of categories. Fortunately, you do not need to write any code to have such a list of post displayed. This can all be done by providing the appropriate parameters in the URL e.g.:
http://mysite.com/?cat=for-boys,6-12-months
for-boys and 6-12-months are the slugs of the corresponding categories.
If you have pretty URLs, it’d look like this:
http://mysite.com/category/for-boys,6-12-months
This will show you posts belonging to either category. What we actually want are posts belonging to both categories. In order to get this result, you need to replace the comma by a plus sign:
http://mysite.com/?cat=for-boys+6-12-months
If you have pretty URLs, it’d look like this:
http://mysite.com/category/for-boys+6-12-months
Instead of “category” you can use “tag” for post tags or “author” for post authors.
Thanks dude. That’s i was looking for. It worked well!
Thank you! this was helpful.
Thanks a lot for this tipp. Exactly what I was looking for
Cheers from Germany
Hansjörg
Hi
I just realized that in my other WP-Site this does noch work, because I removed the slug ‘category’. So a category page Looks not like mysite.com/category/for-Boys but mysite.com/for-Boys.
Is there nevertheless a way to Combine more than one category in the way you described?
Perfect, thank you! Have been struggling with this for some time.
great stuff
i’m using this format which mostly works https://the5krunner.com/category/news,review/
some of the other formats didn’t work for me even though i see them working as you sate on your .de site.
is there any way to sort the results? in the example above my REVIEW category seems to display AFER all of the NEWS items and it’s a LONG list 😉
thank you for the tip though
(ideally i want to display every post as a link on a mobile menu to avoid my cluttered desktop home page theme, i’ll add this category method as a partial workaround)
Hi,
This works for post categories, I would like for woocommerce product categories and then this doesn’t work and I guess it’s ?cat= I need to change but to what?
Thanks,
Annika
Perfect, exactly what I was looking for! Just to clarify for others: Under “Add menu items”, select “Custom Links” and write the URL. “Link text” is the name you choose for the menu item, for example, “Boys 6-12 months”.
Great tip! was looking for this workaround for my blog! Saved me time figuring this out.