Posted By

fredi1993 on 10/10/17


Tagged


Versions (?)

Filter products based on their category


 / Published in: PHP
 

Filter products based on their category

  1. add_action('pre_get_posts','shop_filter_cat');
  2.  
  3. function shop_filter_cat($query) {
  4. $parentt=$query->queried_object->post_parent;
  5. $titlee=$query->queried_object->post_title;
  6.  
  7. if (!is_admin() && $parentt==9773 && $query->is_main_query()) {
  8.  
  9. $query->set('tax_query', array(
  10. array ('taxonomy' => 'product_cat',
  11. 'field' => 'slug',
  12. 'terms' => $titlee
  13. )
  14. )
  15. );
  16. }
  17. }

Report this snippet  

You need to login to post a comment.