pre_get_posts and Layered Nav Filter widget compatibility issue
-
This is link to dev website: https://beta.projectswatches.com/?filter_color=aqua
it has Layered Nav filters enabled for custom attributes, and it has custom code in functions.php of active theme:add_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); function custom_pre_get_posts_query( $q ) { if ( ! $q->is_main_query() ) return; if ( ! $q->is_post_type_archive() ) return; if ( ! is_admin() && is_shop()) { $q->set( 'tax_query', array(array( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => array( 'watch-archives-category', 'gift-cards' ), // Don't display products in the archive category on the shop page 'operator' => 'NOT IN' ))); } remove_action( 'pre_get_posts', 'custom_pre_get_posts_query' ); }
I got this code from this page: https://docs.woocommerce.com/document/exclude-a-category-from-the-shop-page/
The theme itself doesn’t have any other modifications. All plugins are deactivated exept for woocommerce. All components – wordpress, woocommerce, theme – all latest version.
The problem is: the Layered Nav attribute filter doesn’t work along with pre_get_post snippet. You may choose attributes from filter, but page will still showing all products.
The question is: how to make it work properly? Is this a woocommerce bug?
- The topic ‘pre_get_posts and Layered Nav Filter widget compatibility issue’ is closed to new replies.