Skip Navigation

[Resolved] Excluding category from default view, but keep in search

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 17 replies, has 1 voice.

Last updated by allisonD 5 days, 3 hours ago.

Assisted by: Minesh.

Author
Posts
#2814578

Hello! I am working on our employee directory. Employee is a post type, Employee Type is a taxonomy, and there are 3 categories in that taxonomy: faculty, staff, and emeritus. I've been using a directory view for a while: hidden link
However, I'd like the default view of this view/page to show ONLY faculty and staff, BUT still have "emeritus" as an option in the search bar. I added
wpv-employee-type="faculty,staff"
to the shortcode, but Emeritus employees are still showing.
I wondered if it had something to do with the Query Filter I have set in the back, but now when I try to remove it, it returns when I refresh the page after deleting and saving, so it must be important:
Select posts with taxonomy:
Employee Types slug in one of those set by the URL parameter wpv-employee-type
AND
Filter based on the frontend search filter by Academic Program Areas.

SECONDARILY, I'm wondering if there's a way to make a URL display for this view/page for a field not used in the display or search of this view (in this case, Department, which is a category taxonomy of Employee).

Thank you!!

#2814605

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

As I understand - on the following page:
- hidden link

Your goal is to remove the "emeritus" taxonomy trem displayed with the "Employee Types" mutlti select box - is that correct?

#2814649

No, I want to remove anyone tagged as Emeriti from showing in the default view, but keep them as options in the search box. So the default view acts as if a search was done where only Faculty and Staff were selected.

#2814723

Minesh
Supporter

Languages: English (English )

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

We will have to use view's filter hook "wpv_filter_query".

Can you please share admin access details and let me check what would be the possible solution in your case.

*** 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.

#2814743

Unfortunately admin access to our website is only available on our network, by our IT department policy, so I can't share access. Any info you can provide to guide me to the right page, settings, snippets, etc. would be greatly appreciated.

#2814834

Minesh
Supporter

Languages: English (English )

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

I would like to know - later on when user select the option "Emeritus" from the "Employee Types" filter - do you want to show posts belongs to "Emeritus"?

#2815145

Yes, that would be ideal. Still have it be a filterable option, but not show by default.

#2815209

Minesh
Supporter

Languages: English (English )

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

Can you please try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/

add_filter( 'wpv_filter_query', 'exclude_aaa_by_slug_on_initial_load', 10, 3 );
function exclude_aaa_by_slug_on_initial_load( $query_args, $view_settings, $view_id ) {
   
    $taxonomy_slug  = 'employee-type'; // Replace with your taxonomy (e.g. 'category')
    $exclude_term_slug = 'emeritus'; // The slug of the term to exclude

    if ( $view_id == 21529) {
        $is_ajax      = defined( 'DOING_AJAX' ) && DOING_AJAX;
        $has_filters  = !empty( $_GET ) || !empty( $_POST );

        if ( ! $is_ajax && ! $has_filters ) {
            $query_args['tax_query'][] = array(
                'taxonomy' => $taxonomy_slug,
                'field'    => 'slug', // use slug here
                'terms'    => array( $exclude_term_slug ),
                'operator' => 'NOT IN',
            );
        }
    }

    return $query_args;
}

More info:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

Can you please try to use the above code and check if that help you to resolve your issue.

#2815465

Hi Minesh, I added the snippet, tested it without error, and activated it and ran it again. Unfortunately the Emeriti categorized folks are still showing in the view on hidden link

#2815500

Minesh
Supporter

Languages: English (English )

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

Can you please try to use the following code:

add_filter( 'wpv_filter_query', 'exclude_term_by_slug_on_initial_load', 10, 3 );
function exclude_term_by_slug_on_initial_load( $query_args, $view_settings, $view_id ) {
    
    $taxonomy_slug  = 'employee-type'; // Replace with your taxonomy (e.g. 'category')
    $exclude_term_slug = 'emeritus'; // The slug of the term to exclude
 
    if ( $view_id == 21529) {
       // $is_ajax      = defined( 'DOING_AJAX' ) && DOING_AJAX;
        $has_filters  = !empty( $_GET ) || !empty( $_POST );
 
        if ( ! $has_filters ) {
            $query_args['tax_query'][] = array(
                'taxonomy' => $taxonomy_slug,
                'field'    => 'slug', // use slug here
                'terms'    => array( $exclude_term_slug ),
                'operator' => 'NOT IN',
            );
        }
    }
 
    return $query_args;
}

- Please make sure to adjust the correct View ID and $taxonomy_slug and $exclude_term_slug if required.

#2816086

I confirmed the view ID and two slugs were right. Added code, tested without error, reactivated, and emeriti are still showing.

#2816153

Minesh
Supporter

Languages: English (English )

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

Well - It should work. What if you increase the priority of the hook to 101.

What if you try to use the following code:

add_filter( 'wpv_filter_query', 'exclude_term_by_slug_on_initial_load', 101, 3 );
function exclude_term_by_slug_on_initial_load( $query_args, $view_settings, $view_id ) {
     
    $taxonomy_slug  = 'employee-type'; // Replace with your taxonomy (e.g. 'category')
    $exclude_term_slug = 'emeritus'; // The slug of the term to exclude
  
    if ( $view_id == 21529) {
       // $is_ajax      = defined( 'DOING_AJAX' ) && DOING_AJAX;
        $has_filters  = !empty( $_GET ) || !empty( $_POST );
  
        if ( ! $has_filters ) {
            $query_args['tax_query'][] = array(
                'taxonomy' => $taxonomy_slug,
                'field'    => 'slug', // use slug here
                'terms'    => array( $exclude_term_slug ),
                'operator' => 'NOT IN',
            );
        }
    }
  
    return $query_args;
}

Does that helps?

#2816406
Screenshot 2025-07-16 142450.png

Unfortunately they're still showing. Is there any code from the view or settings from any taxonomies it would help if I shared?

Also posting a screenshot of the custom code screen in case something there is wrong!

#2816529

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Minesh is not available today. He will get back to you soon. Sorry for the inconvenience and we appreciate your patience.

#2816644

Minesh
Supporter

Languages: English (English )

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

No - the screenshot you shared seems to be Ok.

I need either admin access details or you can send me duplicator copy of your site.

Here is the Doc that you should follow in order to send me duplicator copy of your site:
=> https://toolset.com/faq/provide-supporters-copy-site/

I have set the next reply to private which means only you and I have access to it.