• Resolved sgmecms

    (@sgmecms)


    Hi,

    I’m having a bit of trouble trying to exclude a term, from the search results.
    The following is what i have, it’s all products from the 322 term i want to exclude, but it doesn’t work. Any ideas why?

    function my_aws_terms_exclude_product_cat( $terms ) {
    	$terms[] = 322;
    	return $terms;
    }
    add_filter( 'aws_terms_exclude_product_cat', 'my_aws_terms_exclude_product_cat', 999 );

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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author ILLID

    (@mihail-barinov)

    Hello,

    This filter exclude terms archive pages from the search. Not products with specified terms.

    To exclude products by terms you can use PRO plugin version or try to use following code snippet

    add_filter( 'aws_exclude_products', 'aws_exclude_products' );
    function aws_exclude_products( $filtered ) {
    
        $args = array(
            'posts_per_page'      => -1,
            'fields'              => 'ids',
            'post_type'           => 'product',
            'post_status'         => 'publish',
            'ignore_sticky_posts' => true,
            'suppress_filters'    => true,
            'no_found_rows'       => 1,
            'orderby'             => 'ID',
            'order'               => 'DESC',
            'lang'                => '',
            'tax_query'           => array(
                array(
                    'taxonomy'            => 'product_cat',
                    'field'               => 'id',
                    'terms'               => array( 322 ),
                    'operator'            => 'IN',
                    'include_children' => true
                )
            )
        );
    
        $posts = get_posts( $args );
    
        foreach( $posts as $post_id ) {
            $filtered[] = $post_id;
        }
    
        return $filtered;
        
    }
    • This reply was modified 6 years, 6 months ago by ILLID.
    Thread Starter sgmecms

    (@sgmecms)

    Thank you, it works!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Exclude terms’ is closed to new replies.