How do I add filter with woocommerce categories?


I have created a loop that displays products, however I have ran into a problem when trying to filter them. I have added in tax_query because that is how to filter the search with taxonomies(based on my understanding). I have obtained the current urls term to filter with $term_search = get_queried_object()->slug; and I have echo’d it out to make sure it was outputing the right information.

How do I get my filter to work properly? One thing to mention, I have changed my permalink for the categories, does that effect my slug?

                $term_search = get_queried_object()->slug;
                // WP_Query arguments
                $args = array(
                    'p'                      => 'product',
                    'post_type'              => array( 'product' ),
                    'order'                  => 'ASC',
                    'post_per_page' => 20,
                    'tax_query' => array(
                            'taxonomy' => 'product_cat',
                            'field'    => 'slug',
                            'terms' => $term_search, // (the name of what you want to filter by (latest or whatever))
                        'include_children' => true,
                        'operator' => 'IN'
davidb3rn 4 months 0 Answers 11 views 0

Leave an answer