has_category() for parent category

To do what you want, you’ll need to get a list of all the child categories of the category you want, and then check those. But you don’t need to write that list manually. You can use get_term_children() to get the IDs of the child and grandchild categories:

$cat_id   = get_cat_ID( 'FAQ' );
$children = get_term_children( $cat_id, 'category' );

if ( has_category( $cat_id ) || has_category( $children ) ) {

}

Leave a Comment

error code: 523