[Resolved] Get parametric search values to find text WITHIN, not EQUAL TO a custom field
This thread is resolved. Here is a description of the problem and solution.
Problem:
Parametric search with checkbox field with OR condition
Solution:
You can use views 'wpv_filter_query' hook to modify the view query on fly and establish OR condition between checkbox field using some custom code.
I am trying to set up a parametric search that will allow me to:
- Do a keyword search on all posts
- Filter the results by category (using dropdown selection)
- and/or filter the results by the content of one custom field (using checkboxes to allow for checking multiple options)
- and/or filter the results by the content of another custom field (using checkboxes to allow for checking multiple options)
The custom fields are not numeric, they are text (one has values: Easy,Intermediate,Advanced, the other: Introductory,Overview,Further,Specialised).
I can get this to work using IN as comparison function. But the problem is that some of my custom fields the values are combined (e.g. the value in one says 'easy to intermediate'). I'd like this to also be picked up when filtering (ideally by both 'easy' and 'intermediate' options).
So, is there a way to set the filter up so that the determined values are not EQUAL to the value in the custom field, but are CONTAINED in the value in the custom field? E.g. so that when I check 'Easy', it will find things with field that says 'Easy', but also 'Easy to intermediate', 'Pretty easy', etc.
Here is the URL I am trying to get this on: hidden link
I'm sorry, I wasn't clear in my post. I don't want to create a view where I can display filtered results to the users. I want to create a view which will allow the users to search for posts on the site and filter the results by the content of custom fields. I used this guide to work my way into it: https://toolset.com/documentation/user-guides/front-page-filters/
I want to create an 'advanced search' page for my site, with filtering options as shown on the attached picture (or under the address I pasted above). To create those filters, I created a parametric search view and added them as on the other attached picture. But while the view has no problem filtering by the value 'Specialised reading' (see pic), it fails to find anything when searching for 'urther', while I would like it to be able to pick up all posts which have a value 'Further reading' in the relevant field. The reason why I want that is because some posts will have a value 'Specialised or further reading', or something yet different containing the word 'Further'.
Thanks Minesh,
As far as I can see, there is no 'LIKE' function for the checkboxes input kind. See pic below. The functions don't come up at all in the code displayed on the view page, so I can't change it manually there either. Is there some other way to add it?
Actually checkboxes type uses serialized array to store data to database. That is the reason option "Like" is not available. If you will change your field type to select then "LiKE" option will be available.
The problem is, I do want the users to be able to select several options (e.g. search for both easy and intermediate texts) and the 'select' type only allows you to select one value per filter. Is there any other way to get the desired functionality? Maybe at least some way to put an OR between two 'select' filters?
I don't understand what you meant by trying "wpv_filter_query". I read through the documentation under the link you sent, but I find it quite unclear or I'm just not skilled enough to know what to do with it. Can you explain in more basic terms please?
Alternatively, if it's not possible to do what I need with Views, can you recommend a search plugin which will:
- search and filter by custom types fields
- have the LIKE function for checkboxes type
- display search results in the same way they are displayed using Views
Unfortunately I do not have any other plugin to recommend you that work like views.
Could you please change your search field to checkboxes and send me temporary access details and I'll try if I can fix your issue.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
It does, thanks! But when I check both 'Further' and 'Specialised', it doesn't return anything at all. I'd like it to return a list of all entries which have either 'further' or 'specialised' (or both) in the field. That's the whole point of having checkboxes rather than select or radio buttons.
I tried to paste the same code to the functions.php on the live website and that doesn't work, though. Can I just confirm that's the file that's in the theme folder? Is there a specific place in it where this should be pasted?
Meanwhile - would you be able to help with the alphabetical display of content archive views as well? (mentioned in the previous post) It's ok if not, but please let me know.
Glad to know that your original issue is resolved.
May I kindly ask you please to open a new ticket for your additional question? This will help other users with similar problems to find solutions when searching the forum.
Sure!
Can you please first explain how to make this work on the live website as well? It only works on the test site. I tried to add the code to functions.php in my theme, and to copy the entire functions.php from the test installation to the live one, but it still doesn't want to work on the live site.