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! 🙂
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
My issue is resolved now. Thank you!