Tell us what you are trying to do?
The client needs to search one field for multiple values. (Specifically they want to search the Listing_ID field for a few ID's, preferably by submitting a comma-delimited, or space delimited list).
Using the multi-select functionality won't work because we'd have to load 60K ID's into the dropdown, it would crush the page performance.
Another idea - is it possible to parse the search field before it goes to the db? Is there a filter I can use to do that before a search is made?
Is there any documentation that you are following?
No I can't find any on this.
Is there a similar example that we can see?
If you do a search on a search engine - you can search for multiple words at once.
What is the link to your site?
hidden link
The client needs to search one field for multiple values.
You can set this up using a Query Filter configured to use the "IN" operator, and a text filter input. See the screenshot here for the Query Filter configurations. If you cannot see the Query Filter panel in your View editor screen, scroll to the top right corner and click "Screen Options" to enable the Query Filter panel.
Here is an example of the filter control shortcode:
[wpv-control-postmeta type="textfield" field="wpcf-book-single-line-1" url_param="wpv-wpcf-book-single-line-1"]
Your client can enter comma-separated values in the filter input to search for posts with custom fields matching any of those values.
Another idea - is it possible to parse the search field before it goes to the db? Is there a filter I can use to do that before a search is made?
Yes, there is a PHP API specifically for this called wpv_filter_query:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Click "More usage examples" to see some PHP examples using this filter.
Christian,
Ok this is great, I think this will work.
One question on the wpv_filter_query:
Am I able to call this on page load (before a search is made?). I would like to setup some filters that are in the search by default (that are not going to be controlled by the user).
I tried echoing out the meta_query param and it's empty on page load (works great after a search is made though),
Any ideas/help is huge thank you!
T
Am I able to call this on page load (before a search is made?). I would like to setup some filters that are in the search by default (that are not going to be controlled by the user).
Yes, you can use wpv_filter_query to manage the results before the page is loaded, but it's usually easier to set these filters in the Query Filter section of the View editor screen if possible. If you cannot see the Query Filter, scroll to the top right corner of the View editor screen and click "Screen Options" to enable the panel.
Christian,
This is super helpful, I hope to have this tested today, more very shortly,
T
Great, I will stand by for your update. I am not available on Fridays or Saturdays but I will return Sunday. If you need assistance before then feel free to create another ticket.
Christian,
Having a tough time here on one thing:
I'm just trying to remove one of the filters from the top "Query Filter" section. I'm just trying to remove one of the filters and it's giving me an error, saying:
"Only lowercase letters, numbers, hyphens and underscores allowed as URL parameters".
For virtually every field that was added up on that top section (roughly 30 filters up there).
What is odd is - I didn't manually add any of the query params to this top section (I used toolset to add them). Now it's telling me to change them all to lowercase - won't this now break the query functionality?
Here's what I'm seeing now:
hidden link
How do I get around this error message?
Any thoughts?
Thanks again,
T
Christian that worked! You rock!
The "IN" query filter worked great w/ commas.
Also I was able to get around this last issue and save the query filters.