Skip Navigation

[Resolved] Need Range filter in Toolset (from/till) Part 2

This support ticket is created 2 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 9 replies, has 2 voices.

Last updated by Waqar 2 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#2404407

I'm sorry I have to reopen ticket https://toolset.com/forums/topic/need-range-filter-in-toolset-from-till/page/2/
I am working on so many projects at the same time now, I was unable to respond in time.

1/ losing the AJAX feature really hurts as it requires an extra click from the visitor. Is there a workaround to still be able to benefit from AJAX filtering?
2/ I followed the steps in the last reply in the previous ticket, but filtering does not work. I set a price of eg. €10.000 which should result in 0 results, still both cars are visible. No matter which From or Till price I set, I get 0 results.

#2405685

Hi,

Thank you for contacting us and I'd be happy to assist.

As the other ticket is closed now, the website's access details have been removed from it.

Can you please share the temporary admin login details again? I'll be in a better position to review the setup and share some recommendations, accordingly.

Note: Your next reply will be private and it is recommended to make a complete backup copy, before sharing the access details.

regards,
Waqar

#2406693

The access details worked, thank you.

I'm currently performing some tests on my website, with a similar setup and will share the findings, as soon as this testing completes.

Thank you for your patience.

#2406857

Thank you for waiting.

I've reviewed the view "Voertuigen Filter" used on the page "Voertuigen" and here are my findings:

1/ losing the AJAX feature really hurts as it requires an extra click from the visitor. Is there a workaround to still be able to benefit from AJAX filtering?
- I'm not sure, why Luo suggested turning off the AJAX option in the other ticket, but, based on my testing, it works as expected.

I've enabled it in your website's view and you're welcome to test it as well and let me know if you see something out of place.

2/ I followed the steps in the last reply in the previous ticket, but filtering does not work. I set a price of eg. €10.000 which should result in 0 results, still, both cars are visible. No matter which From or Till price I set, I get 0 results.
- The filtering was not working correctly on your website because, you've added the prices in the custom field as a decimal value, for example, "27.733", "28.300", and "30.990" etc.

I understand that you've used the "." here as a thousand separator and for formatting purposes, but mathematically it is treated as a decimal value, within one hundred (100). As a result, the filtering fails as it is comparing values in thousands and not under 100.

As a quick fix, I've updated the custom values passed in the search field filters shortcode to also use decimal values and it seems to be working now.

Old shortcodes for the price search field:


[wpv-control-postmeta display_values="€ 0,€ 10.000, €20.000,€ 30.000,€ 40.000,€ 50.000" values="0,10000,20000,30000,40000,50000" field="wpcf-prijs" type="select" source="custom" url_param="wpv-wpcf-prijs_min"]
[wpv-control-postmeta display_values="tot,€ 10.000,€ 20.000,€ 30.000,€ 40.000,€ 50.000,€ 60.000,€ 70.000,€ 80.000,€ 90.000,€ 100.000" values="100000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000" field="wpcf-prijs" type="select" source="custom" url_param="wpv-wpcf-prijs_max"]

Updated shortcodes for the price search field:


[wpv-control-postmeta display_values="€ 0,€ 10.000, €20.000,€ 30.000,€ 40.000,€ 50.000" values="0,10.000,20.000,30.000,40.000,50.000" field="wpcf-prijs" type="select" source="custom" url_param="wpv-wpcf-prijs_min"]
[wpv-control-postmeta display_values="tot,€ 10.000,€ 20.000,€ 30.000,€ 40.000,€ 50.000,€ 60.000,€ 70.000,€ 80.000,€ 90.000,€ 100.000" values="100.000,10.000,20.000,30.000,40.000,50.000,60.000,70.000,80.000,90.000,100.000" field="wpcf-prijs" type="select" source="custom" url_param="wpv-wpcf-prijs_max"]

However, I'll recommend not to store the price values with the thousand separators and store only raw numeric values, e.g. "27733", "28300", and "30990" etc, since that is their true mathematical representation.

To show these raw numerical values on the front-end formatted with a thousands separator, you can use a custom shortcode to convert their output, as suggested in this reply:
https://toolset.com/forums/topic/i-want-to-arrange-my-homes-by-price-lowest-to-highest/#post-1951997

Note: I've also commented out the custom code snippet "range-filters" added in the Toolset's custom code section, as it doesn't seem to be needed.

#2408449

Note: I've also commented out the custom code snippet "range-filters" added in the Toolset's custom code section, as it doesn't seem to be needed.

I believe your colleague added the code snippet because Toolset is unable to have 2 range filters at the same time (kilometerstand from/to + price from/to). As you can see on both frontend pages, price works fine, but kilometerstand does not work at all. In the backend I see a comparison String Equal to, which is wrong. But no matter how many times I set it to Number Between, it defaults back to String Equal.

hidden link
hidden link

We need to launch this website next week, so we really hope to finally fix this issue, it's been a few months now and it still is not fixed in a reliable way. I believe 2 range filters from/to are nothing exotic and may even be rather common in filters.

#2408877

Thanks for writing back.

I can understand what the custom code from Luo does, but my tests so far show that it is not absolutely, required.

1. Page "Voertuigen" using the view "Voertuigen Filter":

When I test the 'kilometerstand' filter on this page, it seems to work.

5.000 km to 10.000 km shows 1 result with 6635 km
( screenshot: hidden link )

20.000 km to 30.000 km shows 1 result with 20785 km
( screenshot: hidden link )

Note: I've updated the view's search settings so that all search filter values are shown and they're not changed with the search.
( screenshot: hidden link )

2. Page "Showroom" using the view "Voertuigen Filter - Nieuw":

Very strangely, the search on this page doesn't seem to work correctly, even though the settings and the search filter shortcodes are almost the same as in the other view (except for the "Categorie").

Even with the same setup on my test website, I couldn't reproduce this issue, so it seems something specific to your website is involved.

Do I have your permission to download a clone/snapshot of this website, to investigate this on a test server?

#2410943

Hello Waqar,

"Note: I've updated the view's search settings so that all search filter values are shown and they're not changed with the search."
Do you think it is good UX to always show all search values or is it better to narrow them down after each filter? Or does that cause issues with the filtering?

"Do I have your permission to download a clone/snapshot of this website, to investigate this on a test server?"
Yes, you can clone the site.

#2411339

> Do you think it is good UX to always show all search values or is it better to narrow them down after each filter? Or does that cause issues with the filtering?

- This can vary based on the type of search that is being offered. For example, if there are a lot of search fields available, it would be more convenient if the search options are narrowed down with each field's change. The search form will only show those options which can produce some results.

However, the downside of this option is that you can't go back to pick a different option, once the search has been narrowed down and you have to use the reset button to start all over again.

So, for a search form with few fields (like yours), I feel it is better to show all search values.

> Yes, you can clone the site.

- I wasn't able to log in to the admin area using the access link, so it looks like it has expired. Can you please share the new access link?

I've set your next reply as private.

#2412181

Thank you for the admin access link and I've downloaded the duplicator package from the website.

I'm currently running some tests and will share my findings, as soon as this testing completes.

Thank you for your patience.

#2413031

Thank you for waiting.

I noticed that the view "Voertuigen Filter - Nieuw" which was earlier used on the "Showroom" page was now being used on the "IN DE KIJKER" page.

During troubleshooting on your website's clone, I was able to fix the search filters for the price and mileage fields in this view, by removing their existing query filters and the code for their search fields and then adding them again.

Here are the steps:

1. First, I removed the HTML and shortcodes for these two fields from the "Search and Pagination" section.
( screenshot: hidden link )

2. After saving the view, it showed the message to remove the query filter for these fields too and I selected "Yes".
( screenshot: hidden link )

3. Next, using the "Add Filter" button, I added the search filters for both these fields, making sure to select the correct field type (select), comparison type (numeric), and comparison operator (between).
( screenshot: hidden link )

Here is what the HTML code and the shortcodes for these search fields look like:


<div class="form-group">
	<label for="wpv-wpcf-prijs_min">[wpml-string context="wpv-views"]Prijs[/wpml-string]</label>
	<div style="display:flex">
	[wpv-control-postmeta values="0,10000,20000,30000,40000,50000,60000" display_values="€ 0,€ 10.000,€ 20.000,€ 30.000,€ 40.000,€ 50.000,€ 60.000" field="wpcf-prijs" type="select" source="custom" url_param="wpv-wpcf-prijs_min" ]
	[wpv-control-postmeta display_values="tot,€ 10.000,€ 20.000,€ 30.000,€ 40.000,€ 50.000,€ 60.000,€ 70.000,€ 80.000,€ 90.000,€ 100.000" values="100000,10000,20000,30000,40000,50000,60000,70000,80000,90000,100000" field="wpcf-prijs" type="select" source="custom" url_param="wpv-wpcf-prijs_max"]
	</div>
</div>


<div class="form-group">
	<label for="wpv-wpcf-kilometerstand_min">[wpml-string context="wpv-views"]Kilometerstand[/wpml-string]</label>
	<div style="display:flex">
		[wpv-control-postmeta display_values="0 km,5.000km,10.000 km,20.000 km,30.000 km,40.000 km" values="0,5000,10000,20000,30000,40000" field="wpcf-kilometerstand" type="select" source="custom" url_param="wpv-wpcf-kilometerstand_min"]
		[wpv-control-postmeta values="100000,5000,10000,20000,30000,40000,50000,75000,100000" display_values="tot,5.000 km,10.000 km,20.000 km,30.000 km,40.000 km,50.000 km,75.000 km,100.000 km" field="wpcf-kilometerstand" type="select" source="custom" url_param="wpv-wpcf-kilometerstand_max"]
	</div>
</div>

You can also test these changes on your website's "IN DE KIJKER" page and the search is working as expected.

Note: Earlier, the search field filters may be failing because the type of these custom fields was set to the single-line text field. But now they're correctly set to a number type field, so it shouldn't be an issue anymore.