John Davidson

php - Unable to hide categories within the archive loop

0 comments
Message:


I am using the events calendar plugin from Modern Tribe. I am attempting to hide a specific event category from the archive views. I have added the following code to functions.php but it give me some weird results. On the initial page load, the events with the specified category to exclude are indeed not visible, but if you paginate forward and then back again, the events appear with the category I am trying to exclude.


I have written to the plugins support team who are also baffled as to why this code will not work. I am hoping someone here might shed some light.


add_action( 'pre_get_posts', 'exclude_events_category' );

function exclude_events_category( $query ) {
if(is_post_type_archive( $post_types = 'tribe_events' )) {
$query->set( 'tax_query', array(

array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => 'online',
'operator' => 'NOT IN'
)
)
);
}
return $query;
}


My Answer:
>set( 'tax_query', array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'slug',
'terms' => array( 'category-to-exclude' ),
'operator' => 'NOT IN'
)
) );
}
}

This code should exclude the events with the specified category from the archive views. Make sure to replace 'category-to-exclude' with the actual slug of the category you want to exclude. If the issue persists, you may need to further investigate the plugin's code or consult with the plugin's support team for a more specific solution.

Rate this post

5 of 5 based on 2809 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us