wp query – Exclude post with taxonomy and from the terms (taxonomy & tag) posts count

Question

Using the below code, i have excluded the taxonomy (slug:expired) from archive or tag or taxonomies pages in front-end.

add_action('pre_get_posts','custom_get_posts');
function custom_get_posts($query) {
    
  if ( !is_admin() && $query->is_main_query() ) {
        $taxquery = array(
            array(
                'taxonomy' => 'current-status', 
                'field' => 'slug',
                'terms' => array( 'expired' ),
                'operator' => 'NOT IN'
            )
        );
        if( $query->is_post_type_archive( 'job' ) || $query->is_tag() || $query->is_tax() || $query->is_search() || $query->is_term() || $query->is_category() ){ 
          $query->set('tax_query', $taxquery );
        }
    }
}

The function excluded all the posts tagged to the taxonomy “expired”.

However, the term or tag post counts shows all or entire posts count. How to exclude the posts from the count?
for example: without the taxonomy[expired], posts in the taxonomy[phd-positions] is 700 https://nviewscareer.com/position/phd/. But in the term counts it shows 3453 posts which includes the taxonomy[expired].
term count with taxonomy 'expired'

0
praba 4 months 2022-04-12T11:59:57-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse