Skip Navigation

[Resolved] Legacy View Category Filters Not Quite Working

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 replies, has 1 voice.

Last updated by Timothy 4 days, 6 hours ago.

Assisted by: Minesh.

Author
Posts
#2818390

This is a continuation from a previous ticket here:

https://toolset.com/forums/topic/creating-filters-for-woocommerce-product-view/

The issue is that even though the custom code specifies which categories to show in the filters, in the results it shows all the products, even from categories outside the ones specified (for example the first few products shown are not from any of the specified categories).

hidden link

add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'prefix_modify_get_terms_args', 10, 3 );
 function prefix_modify_get_terms_args( $args, $taxonomy, $view_id ) {
   
if ( $view_id == 82144&& $taxonomy == "product_cat") {
          $args['slug'] = array(
            'watches',
            'sunglasses',
	    'jewelery',
	    'handbags',
	    'signed-memorabilia',
	    'art-entertainment-memorabilia',
	    'sports-memorabilia',
	    'wine-spirits',
    );
}
  return $args;
}

As a side note, on another page I've create another view where the Query Filter uses "Product categories are set by a shortcode attribute", but this seems to have no affect either and shows all the products. Is this a known bug?

Tim

#2818400

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Filtering the terms in taxonomy filters and filtering the results are both different things.

As you already achived one (filtering the taxonomy filter) to display your required terms let me help you to also restrict the posts within those terms.

Just to clarify again, you only want to display posts belongs to the terms you are displaying with your taxonomy filter - correct?

Can you please share admin access details and let me review and check what would be the possible solution.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2818409

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now.

I've added the following code to "Custom Code" section with the code snippet namely "filter-tax-frontend-filter":
=> hidden link

add_filter( 'wpv_filter_taxonomy_frontend_search_get_terms_args', 'func_filter_tax_frontend_filter',10,3);
 function func_filter_tax_frontend_filter( $args, $taxonomy, $view_id ) {
    
if ( $view_id == 82144 && $taxonomy == "product_cat") {
          $args['slug'] = array(
            'watches',
            'sunglasses',
        'jewelery',
        'handbags',
        'signed-memorabilia',
        'art-entertainment-memorabilia',
        'sports-memorabilia',
        'wine-spirits',
    );
}
  return $args;
}

function func_view_with_specific_terms_using_shortcode_attribute($query_args, $view_settings, $view_id) {
     
    global $WP_Views;
   
    $terms_to_display = $WP_Views->view_shortcode_attributes[0]['terms'];
    $terms_to_display = explode(",",$terms_to_display);
  	
   
    if($view_id==82144 ){
        $query_args['tax_query'][] =array(
                'taxonomy' => 'product_cat',
                'field'           => 'slug',
                'terms'        =>  $terms_to_display
            );
    }
    return $query_args;
}
add_filter('wpv_filter_query', 'func_view_with_specific_terms_using_shortcode_attribute', 10, 3);

Can you please confirm it works as expected now.

#2818433

Thanks. Yes this does display only the posts belonging to the terms displayed with the filter. Just one small problem, the price filter has 15,500 as the top price which is the price of one item on my site but that item is not included in any of these filters. So it seems the price filter is still being fed by all the products and not just the ones being displayed, which are all under 2,000.

Tim

#2818562

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That is another issue and I've split the ticket for that issue:
- https://toolset.com/forums/topic/split-legacy-view-category-filters-not-quite-working-product-price-range-filter-doesnt-take-account-of-other-filters/

You're welcome to mark resolve this ticket.

#2818577

Thank you