Skip Navigation

[Resolved] Exclude several taxonomies from a view (PHP code stopped working)

This thread is resolved. Here is a description of the problem and solution.

Problem:
Exclude several taxonomies from a view (PHP code stopped working)

Solution:

You can find the proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/exclude-several-taxonomies-from-a-view-php-code-stopped-working/#post-1167679

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 2 replies, has 2 voices.

Last updated by SimonP3753 6 years ago.

Assisted by: Minesh.

Author
Posts
#1167659

Hi

This issue refers to this previously solved issue: https://toolset.com/forums/topic/exclude-several-taxonomies-from-a-view/

I'm not sure why but the code has stopped working and the anonymous and various terms are appearing again.

hidden link

There has been some change in the views loop editor.

Here's the PHP code:

{code}
add_filter( 'wpv_filter_taxonomy_query', 'func_exclude_specific_terms', 10, 3 );
function func_exclude_specific_terms( $tax_query_settings, $view_settings, $view_id ) {
if($view_id == 7453) { // your view id
$tax_query_settings['exclude'] = array(3410,3575,3641,3348,3079,3280,3694,3397,3636,3264,3204,3160,3557,3395,3026,3665,3399,3724,3687,3645,3284,3487,3183,3184,3116,3373,3597,3287,3288,3076,3407,3075,3605,3379,3393,3599,3119,3606,3144,3188,3027,3074,3592,3608,3609,3679);

}
return $tax_query_settings;
}
{/code}

And the loop:

{code}
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<p>[wpv-taxonomy-link]</p>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
[wpv-layout-end]
{/code}

Many thanks

Simon

#1167679

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - I would like to know where you added the code? I see following code is not added to your theme's functions.php file.

add_filter( 'wpv_filter_taxonomy_query', 'func_exclude_specific_terms', 10, 3 );
function func_exclude_specific_terms( $tax_query_settings, $view_settings, $view_id ) {
if($view_id == 7453) { // your view id
$tax_query_settings['exclude'] = array(3410,3575,3641,3348,3079,3280,3694,3397,3636,3264,3204,3160,3557,3395,3026,3665,3399,3724,3687,3645,3284,3487,3183,3184,3116,3373,3597,3287,3288,3076,3407,3075,3605,3379,3393,3599,3119,3606,3144,3188,3027,3074,3592,3608,3609,3679);

}
return $tax_query_settings;
}

Toolset now offers "custom code" section - you should try to add above code to the same section.
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1167690

That works. I had the code in a PHP snippets plugin which worked previously but now doesn't. Using the Toolset custom code section works, thanks 🙂