Hello, please check my reply here https://toolset.com/forums/topic/filter-display-of-custom-post-taxonomy/#post-2109993
I needed your approval to take a copy of your website and debug it locally.
I checked again the view and the custom code seems to work as expected. I would say, it was just a cache issue during my tests this morning. And now the cache is invalidated and the view does not display the "Ladder Faculty" term anymore. Check this screenshot hidden link
The final code is then:
add_filter('wp_get_object_terms', 'exclude_taxonomy_term', 10, 4);
function exclude_taxonomy_term($terms, $object_ids, $taxonomies, $args) {
global $WP_Views;
$taxonomy = "faculty-fields";
$term_slug = "ladder-faculty";
$view_id = 1723;
if ( $WP_Views->current_view == $view_id ) {
foreach( $terms as $i => $term ) {
//echo $view_id;
//echo $terms[$i];
// print_r($terms);
if ( $term->slug == $term_slug && $term->taxonomy == $taxonomy ) {
unset( $terms[$i] );
}
}
}
return $terms;
}
Let me know if there is something else I can help with.
Yes, please go ahead and take a copy of the site to debug it locally. Thanks.
Also, please let me know how to add additional terms to not be displayed:
$term_slug = "ladder-faculty" ..... ;
To exclude multiple terms, you can update the code at lines 7 and 15 like this:
add_filter('wp_get_object_terms', 'exclude_taxonomy_term', 10, 4);
function exclude_taxonomy_term($terms, $object_ids, $taxonomies, $args) {
global $WP_Views;
$taxonomy = "faculty-fields";
$term_slugs = array("ladder-faculty", "another-term", "third-term");
$view_id = 1723;
if ( $WP_Views->current_view == $view_id ) {
foreach( $terms as $i => $term ) {
//echo $view_id;
//echo $terms[$i];
// print_r($terms);
if ( in_array($term->slug, $term_slugs ) && $term->taxonomy == $taxonomy ) {
unset( $terms[$i] );
}
}
}
return $terms;
}
Notice how I renamed $term_slug into $term_slugs(with an s).
Thank you! The code seems to be working now. Can you please tell me what the issue was before and why the code was not running on our end when we tested? I'd like to document this.
I forgot the following line of code in the first snippet I have shared:
add_filter('wp_get_object_terms', 'exclude_taxonomy_term', 10, 4);
Without this line of code, nothing will be executed. You can read more about hooks here https://developer.wordpress.org/plugins/hooks/
Thanks. Sorry but I'm a bit confused because in your previous message you stated that that line of code did not solve the issue: "Unfortunately, that did not seem to be the only issue. The code does not exclude the term from the results. I need to debug this in my local development environment."
Can you please tell me why you needed to run it locally ?
You are right. But, it was only a cache issue. First, I added the line of code and my tests failed, and I asked for taking a copy of your website to analyze it. Then, it worked. So, my suspicion is that cache was the issue. Check this reply https://toolset.com/forums/topic/filter-display-of-custom-post-taxonomy/page/2/#post-2110285
My issue is resolved now. Thank you!