• Resolved danna556

    (@danna556)


    Hello, i want to exclude specific category and products into her from search and ajax search
    I add following code

    function exclude_terms_from_ajax_search($args)
    {
    
        $args['tax_query'][] = array(
            'taxonomy' => 'product_cat',
            'field' => 'slug',
            'terms' => array('bacon'), // Don't display products in the clothing category on the shop page.
            'operator' => 'NOT IN'
        );
    
       return $args;
    
    }
    
    add_filter('dgwt_wcas_products_args', 'exclude_terms_from_ajax_search');
    add_filter('dgwt_wcas_products_search_page_args', 'exclude_terms_from_ajax_search');

    But doesnt make sense?
    can you help me?

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi danna556,

    Did you find a solution?

    Thanks,

    Richard

    Thread Starter danna556

    (@danna556)

    No, still waiting for plugin’s author reply ??

    • This reply was modified 4 years, 2 months ago by danna556.
    Plugin Author Damian Góra

    (@damian-gora)

    You had wrong filters. Here is solution:

    
    add_filter( 'dgwt/wcas/search_query/args', function ( $args ) {
    
    	$args['tax_query'][] = array(
    		'taxonomy' => 'product_cat',
    		'field'    => 'slug',
    		'terms'    => array( 'bacon' ),
    		'operator' => 'NOT IN'
    	);
    
    	return $args;
    } );
    

    Best
    Damian

    Great! it works.

    Thread Starter danna556

    (@danna556)

    It’s still not working for me? I still had it on ajax search…
    Is there any other filter, that i can try?
    Thank you ! ??

    Thread Starter danna556

    (@danna556)

    Here is also image from my searching bar – https://prnt.sc/up81uj

    Thread Starter danna556

    (@danna556)

    I checked again code working perfect for products, but still shows category name. If i enter slug ‘bacon’ hide all bacon’s products, but category name still stay.

    Plugin Author Damian Góra

    (@damian-gora)

    To exclude a category from search, you have to use different code:

    
    add_filter('dgwt/wcas/search/product_cat/args', function($args){
    
    	$args['exclude'] = array(604);
    
    	return $args;
    });
    

    Replace 604 with the real ID of your term “bacon”.

    Best
    Damian

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Problem with exclude specific category’ is closed to new replies.