Warning: Use of undefined constant closed - assumed 'closed' (this will throw an Error in a future version of PHP) in /home/customer/www/codenegar.com/public_html/wp-content/themes/codenegar/functions.php on line 171
ID Status Date Product
#18330101 Closed WooCommerce Product Filter
Neil Simpson

I currently have the plugin running on a development site and I’m having trouble with incorrect product counts. I have the site set to display subcategories but NOT the child products. WooCommerce handles this ‘reasonably’ but it requires the following code in functions.php to ensure the pagination is correct.

* Remove products in child categories from query to avoid pagination issues
function exclude_product_cat_children($wp_query) {
if ( isset ( $wp_query->query_vars[‘product_cat’] ) && $wp_query->is_main_query()) {
$wp_query->set(‘tax_query’, array(
array (
‘taxonomy’ => ‘product_cat’,
‘field’ => ‘slug’,
‘terms’ => $wp_query->query_vars[‘product_cat’],
‘include_children’ => false
add_filter(‘pre_get_posts’, ‘exclude_product_cat_children’);

However, the product filter does not use this information in the the counts and therefore shows filter as available when they should be empty.

Farhad Ahmadi


“WooCommerce AJAX Product Filter” uses the global WP_Query object to count products.

For example when you are at myshop.com/product-category/mobiles the global WP_Query is limited to the products of that category.

To limit count to a custom condition, you need to change the global WP_Query object of that page (run your function before other filters such this plugin).

You can find more info about product count and the structure of this plugin @

wp-content/plugins/woocommerce-product-filter/filter.php” Line 348

Note the line 349 which declares global $wp_query object.


Write a reply

The ticket has been closed. If you feel that your issue has not been solved yet or something new came up in relation to this ticket, you can re-open it by clicking this link.