Skip Navigation

[Resolved] Conditional Search

This support ticket is created 5 years, 8 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 2 replies, has 2 voices.

Last updated by konstantinosM 5 years, 7 months ago.

Assisted by: Waqar.

Author
Posts
#1267781

Tell us what you are trying to do?
I have created a custom post type and two custom fields (numbers: Min - Max). I want to create a search, where the user will fill ONE field (number). The condition for a post to appear within the results, is the user input number to be between Min and Max.

Is there a similar example that we can see?
You may see this example (hidden link)

What is the link to your site?
Is it under development, nothing much to see there yet! 🙂

#1269027

Hi,

Thank you for waiting while I performed some tests.

To achieve what you're planning, you can follow these steps:

1. You'll first add the two search filters for both your custom fields ( min and max ) as usual, but then adjust their query filters manually, as shown in this screenshot:
hidden link

Note: this setup assumes that expected values entered from visitors can range from 0 to 99999, but feel free to adjust as needed.

2. Next step would be to hide the front-end Max field so that there is just one input field available on the front-end.

You can add a special class "hidden-field" to this field's wrapper and then include custom CSS code, that hides it:
hidden link


.hidden-field {
  display: none;
}

3. The last step would be to include some custom script, to make sure that Max field value is also filled automatically when the value is entered in the Min field:
hidden link


jQuery("input#wpv_control_textfield_wpv-wpcf-book-min").change(function() {
  var newVal = jQuery("input#wpv_control_textfield_wpv-wpcf-book-min").val();
  jQuery("input#wpv_control_textfield_wpv-wpcf-book-max").val(newVal);
});

Note: Please make sure to update the IDs "wpv_control_textfield_wpv-wpcf-book-min" and "wpv_control_textfield_wpv-wpcf-book-max" to match the field IDs on your website.

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1269993

My issue is resolved now. Thank you!