Inicio › Toolset Professional Support › [Resuelto] Min and Max fields in search not returning correct results
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 |
---|---|---|---|---|---|---|
- | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | 7:00 – 14:00 | - |
- | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | 15:00 – 16:00 | - |
Supporter timezone: Europe/London (GMT+00:00)
Etiquetado: Custom search, Toolset Blocks, Views plugin
Documentación relacionada:
Este tema contiene 13 respuestas, tiene 3 mensajes.
Última actualización por MargeP6083 hace 5 años, 1 mes.
Asistido por: Nigel.
I am trying to create a age range search of min (more than or equal) and max (less than or equal) in a page view. Search is set to number. Using the new content block custom search page.
Link to a page where the issue can be seen: enlace oculto
The results are wrong or none at all.
Hello. Thank you for contacting the Toolset support.
I checked on your install and I see that you have created block view that is set to query the "Talent Profiles" post type.
I see the custom fields group is attached to post type "Talent Profiles" is the "Talent Information". Now, within this custom fields group, I see two fields "Minimum Acting Age" and "Maximum Acting Age". If I'm not wrong, you want to filter by these two number fields for the age rage - correct?
Yes, the queries return in correct results when using both or just one number field.
Sorry but as you say it works fine and shows correct results.
To eliminate any confusion/doubt, What combination I should use that you want to report that its not working as expected? Can you please share exact steps, what filters I should use to reproduce the issue?
*incorrect results. Sorry typo.
There are two users in the system right now. If I put in an age range let's say that I'm looking for, the correct result doesn't show.
Example, I am searching for a person who has an age range of 60 min and 70 max. There's a person who has a range that falls within there. His profile doesn't show up. The search fields are set. >= is set for min and =< is set for Max.
It doesn't work even when I use only one search field.
Thanks, I've changed the filter settings on your view's custom search block area for the min and max-age fields.
I've changed the minimum age's comparison value as "lower than or equal to", please check the following screenshot:
=> enlace oculto
And, the maximum age's comparison value as "greater than or equal to", please check the following screenshot:
=> enlace oculto
Then, I searched with the age 60 min and 70 max and I can see the following result:
=> enlace oculto
Can you please confirm it works at your end as well.
Hi, This doesn't work for me.
The user is searching for people in a range. The range should be true if the numbers overlap the range.
Example: User searches for people who fall into age range 49____________71. There is a user who has range 50____70, but that user doesn't show up in the result.
I want to show the users in the range that fall inside the search parameters.
49____________71 - search range, I want to see all users who fall in this range.
50__________70 -True, this person falls in that range.
Min is greater than or equal to 49. (50 is greater than 49)
Max is less than or equal to 71. (70 is less than 71)
It's not working. See link.
enlace oculto
Example: User searches for people who fall into age range 49____________71. There is a user who has range 50____70, but that user doesn't show up in the result.
==>
Considering the values you added to your post: Actual values added to post: Min: 50 and Max: 80
- enlace oculto
If you want to search in within the range 49____________71, then we need to set the filters to
- So, the comparison will be 50 > 49 and 80 > 71
- that means, we need to set the filters as min age >= search value (49) AND max-age is >= search value (71)
But, now:
it will become contrary when you use the search value 60 min and 70 max as you shared in your reply here:
=> https://toolset.com/forums/topic/min-and-max-fields-in-search-not-returning-correct-results/#post-1384163
Actual values added to the post: Min: 50 and Max: 70
- So, the comparison will be 50 > 60 and 80 > 70 (the condition will become false with 50 > 60 )
- that means, filters will be set as as min age actual 50 >= search value (60) AND max-age actual 80 >= search value (70)
- in this case you will not find any result.
For now, I've adjusted the filters as per your within the range 49____________71 value and if you can check it will show the result.
=> enlace oculto
Hi, I'm sorry for the late response, but that doesn't work either. In fact, that page looks broken. I've not been in the admin since my last message to you.
enlace oculto
The age ranges have disappeared from the the profile excerpts. (Why is that?) For example, the man had a range of 50 - 80. The woman has a range of 18-35. That is gone from the search page. enlace oculto I have not edited this page. I'm wondering what happened. This happened before updating any plugins.
(If you are adding custom code, can you post the location and any code you've added?)
I'm not sure why this is so difficult.
When I search for a user min-max of 20-25, I get a wrong response.
The SEARCH RESULT should be the woman who has a range of 18 to 35. She fits that user search.
1. Minimum field should show the user with a MIN number that is EQUAL to or GREATER THAN the number the user inserts in the search box. (20 is greater than 18. True!)
2. Maximum field should return the USER who has a MAX number EQUAL to or LESS THAN 25. (25 is less than 35. True!)
This is big wrong since it shows the man who has a range of 50 - 80 in his profile.
enlace oculto
Can you bump this to the developer who created this part of the app? Maybe something is broken in the code.
I need to have this search feature ready for the customer in a couple days plus other features. I can't move forward until this is fixed.
Thank you
The age ranges have disappeared from the the profile excerpts. (Why is that?) For example, the man had a range of 50 - 80. The woman has a range of 18-35. That is gone from the search page. enlace oculto I have not edited this page. I'm wondering what happened. This happened before updating any plugins.
==>
I do not see any issue with page range or anything. It works just fine: enlace oculto
Maybe you should try to clear the cache as I see you are using plugin SG Optimizer
That is why I shared the information that how the comparison will be applied in backend with the value in my previous reply and how it will compare the actual value in comparison of the search input value.
=> https://toolset.com/forums/topic/min-and-max-fields-in-search-not-returning-correct-results/#post-1386599
If you will check my above reply, how comparison works is bit different than you think.
When I search for a user min-max of 20-25, (the woman who has a range of 18 to 35 that are actual values available)
- filter set minimum age >= search value
- filter set maximum age <= search value
This is how the query will build:
SELECT SQL_CALC_FOUND_ROWS wpae_posts.ID FROM wpae_posts INNER JOIN wpae_postmeta ON ( wpae_posts.ID = wpae_postmeta.post_id ) INNER JOIN wpae_postmeta AS mt1 ON ( wpae_posts.ID = mt1.post_id ) WHERE 1=1 AND wpae_posts.ID NOT IN (239) AND ( ( wpae_postmeta.meta_key = 'wpcf-minimum-age' AND CAST(wpae_postmeta.meta_value AS SIGNED) >= '20' ) AND ( mt1.meta_key = 'wpcf-maximum-age' AND CAST(mt1.meta_value AS SIGNED) <= '25' ) ) AND wpae_posts.post_type = 'talent' AND ((wpae_posts.post_status = 'publish' OR wpae_posts.post_status = 'private')) GROUP BY wpae_posts.ID ORDER BY wpae_posts.post_date DESC LIMIT 0, 10
As you can see:
- minimum age comparision will be translated to:
- 18 >= 20
- maximum age comparison will be translated to:
- 35 <= 25
Both conditions will become false. You need to place actual values.
That is why I shared the solution here, if you set the filter as I suggested with the following reply - you will get the woman who has a range of 18 to 35 when you enter search values min 20 and max 25:
=> https://toolset.com/forums/topic/min-and-max-fields-in-search-not-returning-correct-results/#post-1385775
So, for now, I already set the filters as explained in the above reply.
But, then you again shared another scenario:
49____________71 - search range, I want to see all users who fall in this range.
==>
This range will NOT show the results:
SELECT SQL_CALC_FOUND_ROWS wpae_posts.ID FROM wpae_posts INNER JOIN wpae_postmeta ON ( wpae_posts.ID = wpae_postmeta.post_id ) INNER JOIN wpae_postmeta AS mt1 ON ( wpae_posts.ID = mt1.post_id ) WHERE 1=1 AND wpae_posts.ID NOT IN (239) AND ( ( wpae_postmeta.meta_key = 'wpcf-minimum-age' AND CAST(wpae_postmeta.meta_value AS SIGNED) <= '49' ) AND ( mt1.meta_key = 'wpcf-maximum-age' AND CAST(mt1.meta_value AS SIGNED) >= '71' ) ) AND wpae_posts.post_type = 'talent' AND ((wpae_posts.post_status = 'publish' OR wpae_posts.post_status = 'private')) GROUP BY wpae_posts.ID ORDER BY wpae_posts.post_date DESC LIMIT 0, 10
-- As you can see the minimum age comparision will translate to: 50 <= 49 (which is false)
50__________70 -True, this person falls in that range.
===>
This range will show the results.
SELECT SQL_CALC_FOUND_ROWS wpae_posts.ID FROM wpae_posts INNER JOIN wpae_postmeta ON ( wpae_posts.ID = wpae_postmeta.post_id ) INNER JOIN wpae_postmeta AS mt1 ON ( wpae_posts.ID = mt1.post_id ) WHERE 1=1 AND wpae_posts.ID NOT IN (239) AND ( ( wpae_postmeta.meta_key = 'wpcf-minimum-age' AND CAST(wpae_postmeta.meta_value AS SIGNED) <= '50' ) AND ( mt1.meta_key = 'wpcf-maximum-age' AND CAST(mt1.meta_value AS SIGNED) >= '71' ) ) AND wpae_posts.post_type = 'talent' AND ((wpae_posts.post_status = 'publish' OR wpae_posts.post_status = 'private')) GROUP BY wpae_posts.ID ORDER BY wpae_posts.post_date DESC LIMIT 0, 10
So, all cases for min-max you shared are correct but 49____________71 beause the actual value for min age is set to 50.
Now, when you search for the following range: enlace oculto
- 20-25:
=> it will show you one result with woman pic
- 50-70:
=> it will show you one result with man pic
- 60-70:
=> it will show you one result with man pic
Let me know if you still have any confusion or you want to pass this ticket to support a person who works more closely with your timezone.
It doesn't quite work.
For example, if I search min: 15 max: 20, there are no results returned. The woman should appear since she falls within that scope. She is within that range. There seems to be some operation missing in this range comparison. Is there some way to use "or" to solve this problem? Does that make sense?
The woman is greater than 15 so there would be overlap
18_________________35
15_______20
That wouldn't work either since 15 did not return the correct result.
Search for minimum "15" should result in the woman's profile. And it did not. Used incognito window, so there was no cache.
And when I use the max of "15", it returns both man and woman. That should return nothing. see below screen. SEarch was in incognito window. enlace oculto
Sorry, it would be easier to talk to someone in my timezone.
Idiomas: Inglés (English ) Español (Español )
Zona horaria: Europe/London (GMT+00:00)
Hi Marge
My shift is over but I can see you need a solution—which I have—so let me share it briefly with you, I need to leave soon.
Hopefully it will be sufficient. If you have further problems with it, I suggest you open a new ticket (linking to this one).
You might still catch Shane who is still working today, and if not, Christian will be working in your timezone on Sunday.
The first key thing you need to know is that I'm not sure if you can do this with the new Block Editor for creating Views, and you may have to use the classic Views editor. (I will have time to revisit this on Monday to check, but you can always try yourself.)
I have set a basic version of this up for you which is working.
The View is inserted on this page: enlace oculto
Test it, it should work.
The View can be edited in the Classic mode here: enlace oculto
To make your range search work, I had to swap the labels of the max and min filters and reverse the order (so that when users think they are entering the value for the max filter they are actually entering the value for the min filter and vice versa, and then the actual comparisons are different than you would expect.
I describe how it works in another thread: https://toolset.com/forums/topic/filter-by-range-within-range/#post-501081
I've included the same filters as your original View, you shouldn't have to change much aside from possibly styling.
For the output, I chose a Bootstrap grid, and then the template for each result is made using the Block Editor, which you should be familiar with.
Sorry I can't do more now, open a new ticket for continuing help over the weekend, and feel free to ask anything here that can wait till Monday.
This actually works on the blocks. I just tested. The results work the same. I think others may be interested in knowing how the search fields actually work as well.
My issue is resolved now. Thanks for your help!