Note that is_category()
accepts a category ID, name, slug, or array of such, so you could actually simply use is_category( array( 'Lumber', 'Domestic Hardwoods' ) )
instead of having to call is_category()
twice.
But as for what you asked, is_category()
does not support that, however, what you are trying to do can be achieved like so, which uses get_term_children()
:
if ( ! is_admin() && $query->is_main_query() && $query->is_category() ) {
$current_cat = get_queried_object();
// replace 'parent' with the correct category slug
$parent_cat = get_term_by( 'slug', 'parent', 'category' );
// $parent_cat = get_term_by( 'name', 'Parent', 'category' );
// $parent_cat = get_term( 123 );
// Get the child categories/IDs.
$children = get_term_children( $parent_cat->term_id, 'category' );
$cat_ids = array_merge( array( $parent_cat->term_id ), $children );
// Check whether it's the parent category's archive or its children's.
if ( in_array( $current_cat->term_id, $cat_ids ) ) {
// put your awesome code here...
}
}
So the only hard-coded database value is the parent category’s slug, but you can also use its name or ID, if you want to.