custom post types – Is it possible to make is_category() recursive?

Question

In resetting the main query for category pages for a custom post type, I would like to write one test for a parent category and have it test positive for all child categories, recursively.

For example, if the category is Lumber, I am resetting the main query to pick up data in a Custom Post type for lumber.

Currently, the code looks like this:

    if (!is_admin() && $query->is_main_query() && (is_category('Lumber') || is_category('Domestic Hardwoods')) )

While I can add all the subcategories manually, it would mean inconvenience for my client if they wish to add a new subcategory. Recursion should fix that UX problem.

0
Nora McDougall-Collins 1 month 2022-08-17T12:01:00-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse