Return to Snippet

Revision: 72655
at October 10, 2017 01:06 by fredi1993


Initial Code
add_action('pre_get_posts','shop_filter_cat');

 function shop_filter_cat($query) {
 	$parentt=$query->queried_object->post_parent;
 	$titlee=$query->queried_object->post_title;

    if (!is_admin() && $parentt==9773 && $query->is_main_query()) {

       $query->set('tax_query', array(
                    array ('taxonomy' => 'product_cat',
                                       'field' => 'slug',
                                        'terms' => $titlee
                                 )
                     )
       );   
    }
 }

Initial URL


Initial Description
Filter products based on their category

Initial Title
Filter products based on their category

Initial Tags


Initial Language
PHP