Forums › Forums › Search & Filter Pro › Filter that searches in one field or between two fields
- This topic has 10 replies, 2 voices, and was last updated 4 years, 1 month ago by Anonymous.
-
Anonymous(Private) July 22, 2020 at 10:39 am #253539
Scenario:
– A product has two custom fields (PH and PH_MAX).
– PH is always filled in
– PH_MAX is only filled in if the PH is not exact and it can vary in between values PH and PH_MAXSearch requirements;
– When a visitor searches for PH = 7 it should find any products that ( PH = 7 OR ( PH_MAX != ” and PH <= 7 AND PH_MAX >= 7 ) )Is this possible, even if it’s by using hooks with our custom code?
Ross Moderator(Private) July 22, 2020 at 10:51 am #253545Hi Diogo
The only way I can think of is this setup:
1) You always fill in PH_MAX (even when not needed)
2) You create a Post Meta -> Number Range field, with different start / stop meta keys (using PH and PH_MAX)
3) You use JavaScript on the front end, to show / hide / set the “Max” field according to what the user has pressed – it could be permanently hidden, and you would manipulate the field according to what you needThanks
Ross Moderator(Private) July 22, 2020 at 3:49 pm #2535833) Well, it wasn’t a fully fleshed implementation, but I thought you might need to change this depending on the value you put in for posts that don’t need a max, but you fill it anyway. However, if you set the max field for these posts that wouldn’t use the field normally, to the max value, you might not need to do this step. I’m assuming you want to show one field only not both min/max.
Best
Anonymous(Private) October 1, 2020 at 4:31 pm #261610This was not a very elegant solution.
1) Currently, with the post meta “number” type of field, we can create a range filter that allows us to search a specific range of user-selected values in a range defined by two post meta fields.
Example: https://snipboard.io/1rIUR8.jpg
Results in: https://snipboard.io/S6aCh8.jpgThis will show me all the posts that have a value between the range of x and y on the field _ph_key to _ph_key_max range.
For example, if I search 4 to 5 it will return all posts that have ( _ph_key >= 4 and _ph_key <= 5 ) OR ( _ph_key_max >= 4 and _ph_key_max <= 5 ).
In sum: all posts which range overlaps.2) With the post meta “choice” type of field, we can only search in one specific meta key.
Example: https://snipboard.io/Myoia7.jpg
Results in: https://snipboard.io/2FkOCU.jpgBut this will only search on _ph_key. Not what we need.
3) We need something that is a mix of these situations. We need a single “choice” field populated with all options existing in both _ph_key and _ph_key_max meta fields and search between them.
Example: If I chose “5”, we need it to return all posts that have _ph_key>=5 and _ph_key_max<=5
Is this even possible with this plugin at the moment?
If this is not an option at the moment, how much would it cost for us to sponsorship this new feature and make it available for everyone?Ross Moderator(Private) October 6, 2020 at 7:46 pm #262132Hi Diogo
Just to let you know I’ve not forgotten about this – will pick it up tomorrow.
Thanks
Ross Moderator(Private) October 7, 2020 at 1:39 pm #262209BTW, your field “Subtract” has many many options, I think this will slow down the speed.
Thanks
-
AuthorPosts