I'm trying to remove or filter out a specific taxonomy term from a taxonomy view. There was a support thread about this exact request but the solution provided doesn't appear to be working for me (https://toolset.com/forums/topic/hiding-taxonomy-terms-from-views).
I swear I was able to get this to work in the past, but now I don't know what's going on and why it's not working for me now. Anyway, I have a custom taxonomy called "Departments" and there's one particular term (Owner Operators) that I would like to exclude from my landing page View (seen here: lien caché). As you can see from my link, the section exists on this page when it shouldn't. Here's the code I was utilizing from the previous support thread that was trying to address this issue:
// Remove Owner Operators from Department Views Output
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
$my_views = array(2617);
if( in_array( $views_ID, $my_views ) ) // your view id
{
$query['tax_query'][] = array(
'taxonomy' => 'department', // taxonomy name
'field' => 'slug',
'terms' => array( 'owner-operators' ), // term slug for exclude
'operator' => 'NOT IN'
);
$query['tax_query']['relation'] = 'AND';
}
return $query;
}
I suppose I could use CSS to hide the section, but since each View loop output pulls a couple other Views related to the taxonomy terms, I'd like to reduce how many of those show up on the page if it's possible.
Any help in this matter would be greatly appreciated.
Hello. Thank you for contacting the Toolset support.
I'll have to check how exactly you configure the display of the taxonomy.
Can I've admin access details and let me review your current settings and then I will be able to guide you in the right direction.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I'm aware of this implementation, but I didn't want to use it as it's too specific. If a new term is added, it doesn't get automatically selected for inclusion (see attached screenshot where the term "New Department" is not selected) and in fact defaults to deselected. I need to configure EXCLUSIONS not INCLUSIONS, so that if the client wants to add a new Department, they can freely do so without having to modify the View configuration.
With post views, you can set exclusions in the query filters by post ID, but that is not an option with the taxonomy views, which is why I was trying to use that code in that support thread I had originally linked to.
I suppose I could add in a conditional argument within the View output, to filter out the term(s) I don't want to show on the Careers landing page, but that's such a dirty way of handling these kinds of things. Can you review the code provided by the support rep in the support thread I was referring to in my original post, please, and see why it wouldn't be working for my application?
Just so you know, I deleted that query filter you added as it's not what I'm looking to implement in this application.
Your custom code is establishing a list of inclusions, which is why I didn't want to use that feature in the Query Filters selections in the first place.