Filter products based on their category


/ Published in: PHP
Save to your folder(s)

Filter products based on their category


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.