Please note, this is a STATIC archive of website www.themepunch.com from 28 Sep 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Combine “AND” with “OR” for Category Relation (advanced)

home_topbanner

Let’s say you have two main categories for your posts:

  • Europe
  • Asia

 

And posts from these main categories also have one or more of the same additional categories.

  • Europe
    • Flights
    • Hotels
    • Dining
  • Asia
    • Flights
    • Hotels
    • Dining

 

Now lets say you only want to include posts that have “Europe” as a category, but also only want to include “Europe” posts with either “Flights” or “Hotels”, and NOT “Dining”.

So the logic would be:

(Europe AND Flights) OR (Europe AND Hotels)

This can be accomplished by hooking into one of the plugin’s PHP filters.

1. For the above scenario, choose "Europe", "Flights" and "Hotels" as your Categories, and then choose "OR" for the Category Relation.

and-or-combined

2. Next, add the following PHP code to your theme's "functions.php" file.

In the following code, the number “121” is the Category ID for “Europe”.  Adjust this number accordingly.

Variation of above code for WooCommerce Product Categories.

Variation to include Sub Categories