Kindly replace our previous code with the following,
function aiovg_filter_videos_count( $terms, $taxonomies, $args ) {
if ( is_admin() ) {
return $terms;
}
if ( ! in_array( 'aiovg_categories', $taxonomies ) ) {
return $terms;
}
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$hide_empty = ! empty( $args['custom_hide_empty'] ) ? 1 : 0;
foreach ( $terms as $index => $term ) {
$query_args = array(
'post_type' => 'aiovg_videos',
'posts_per_page' => -1,
'post_status' => array( 'private', 'publish' ),
'fields' =>'ids',
'no_found_rows' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'tax_query' => array(
array(
'taxonomy' => 'aiovg_categories',
'field' => 'term_id',
'terms'=> $term->term_id
)
)
);
$aiovg_query = new WP_Query( $query_args );
if ( $aiovg_query->have_posts() ) {
$term->count = count( $aiovg_query->posts );
} else {
if ( $hide_empty ) {
unset( $terms[ $index ] );
}
}
}
}
return $terms;
}
add_filter( 'get_terms', 'aiovg_filter_videos_count', 10, 3 );
function aiovg_custom_categories_args( $args ) {
if ( isset( $args['hide_empty'] ) ) {
$args['custom_hide_empty'] = $args['hide_empty'];
$args['hide_empty'] = 0;
}
return $args;
}
add_filter( 'aiovg_categories_args', 'aiovg_custom_categories_args' );
Hope this solved your issue!