Skip Navigation

[Resolved] Trying to exclude a taxonomy from a view

This support ticket is created 2 years, 7 months 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 18 replies, has 2 voices.

Last updated by markM-8 2 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#2413307
12b3442a-038b-4d1d-bc18-c89a2253511b.png

Tell us what you are trying to do?
- We have a page that shows all posts but we need to exclude one from the pages results and taxonomy filter - Podcasts
hidden link

Is there any documentation that you are following?
- i have been readign through the support forum

Is there a similar example that we can see?
N/A

What is the link to your site?
hidden link

#2413447

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

Thank you for getting in touch.

You should be able to do this with the function below.
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_frontend_search_available_terms

This allows you to modify the terms that are being retrieved by the frontend filter.

Thanks,
Shane

#2413903

Hi Shane. I have tried this put it did not work. My PHP is a little rust. How woudl you write this to exclude the category "podcast" for a view with an ID of "7664"?

#2413927

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

The code should look like.

add_filter( 'wpv_filter_taxonomy_frontend_search_available_terms', 'prefix_modify_list_of_terms', 10, 3 );
 
function prefix_modify_list_of_terms( $terms, $taxonomy, $view_id ) {
    $curated_terms = array();
if($view_id == 7664){
    foreach ( $terms as $term ) {
        if (  $term->slug != 'podcast' ) {
            $curated_terms[] = $term;
        }
    }
}
    return $curated_terms;
}

Please try this and let me know if it helps.
Thanks,
Shane

#2413961

Hi Shane. I added the code but its still showing Podcasts: hidden link

#2414081

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2022-07-08 at 1.48.08 PM.png

Hi Mark,

I checked the link and saw that the Podcast option was not showing. See Screenshot.

So it appears that the code is working as intended.

Thanks,
Shane

#2415261

Hi Shane, It is not showing in the dropdown because we added this js code:

jQuery(function($){
  var arr=['podcast'];
  $('select[name="wpv-blog-category"] option').each(function(){
    if(jQuery.inArray($(this).val(), arr)>=0){
        $(this).hide();
    }
  });
})

We need to have it removed from the archive itself.

#2415473

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

This solution works as well.

Not sure if you would want to proceed with the PHP hook. If so then you can provide me with admin access so that I can perform further tests to see why the code isn't working.

Thanks,
Shane

#2418257

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

I'm trying to log into the site using the sftp but it doesn't seem to be working. I'm also not able to add any custom code to the site because of the permissions on the wordpress directory.

Thanks,
Shane

#2419791

Hi Shane. I have updated the SMTP details. Can you try now? Please use port 2222 just in case?

#2419953

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

I've added the code to the site, however can you let me know if you're still able to see the Podcast option.

Thanks,
Shane

#2420531

Hi Shane. I had to disable the code as the site was showing a critical error. Can you please check again?
I just commented out the code.

#2420885

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

Where was the code that you commented out located? As the code I added to the site is still active.

Thanks,
Shane

#2421149

I saw it in the functions.php file? Did you add it somewhere else?

#2421873

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mark,

I actually added the code at Toolset->Settings -> Custom Code.

However the code seems to be working given that "podcast" is no longer being shown in the available dropdown options.

Thanks,
Shane