$item['value'], 'taxonomy_slug' => $item['groupSlug'], ]; }, $categories_raw ); $current_queried_id = get_queried_object_id(); $has_post_specified_term = false; $tax_slugs_of_catch_all_items = []; $is_any_catch_all_selected = false; $has_post_specified_taxonomy = false; // Logic evaluation. foreach ( $categories_raw as $item ) { if ( true === $item['isCatchAll'] ) { $tax_slugs_of_catch_all_items[] = $item['groupSlug']; $is_any_catch_all_selected = true; } } foreach ( $categories as $cat ) { if ( has_term( $cat->id, $cat->taxonomy_slug, $current_queried_id ) ) { $has_post_specified_term = true; break; } } $is_displayable = $has_post_specified_term ? true : false; if ( ! $is_displayable && $is_any_catch_all_selected ) { foreach ( $tax_slugs_of_catch_all_items as $tax_slug ) { $has_post_specified_taxonomy = has_term( '', $tax_slug, $current_queried_id ); if ( $has_post_specified_taxonomy ) { break; } } $is_displayable = $has_post_specified_taxonomy ? true : false; } // Evaluation output. return ( 'is' === $display_rule ) ? $is_displayable : ! $is_displayable; } }