Forums › Forums › Search & Filter Pro › Change Search to query an ACF custom field
Tagged: acf, customfield, query
- This topic has 1 reply, 2 voices, and was last updated 4 years, 4 months ago by Trevor.
-
Anonymous(Private) July 20, 2020 at 2:02 am #253261
Hi,
We have a custom post type called ‘councils’. We are assigning multiple postcodes to each of these entries. Example: 3033,3101,3002 etc. These are entered in an ACF custom field called ‘post_codes’ that is a textarea type field and are separated by a comma. See screenshot here:
https://snipboard.io/QxmauH.jpg
On the front end, we have the search form showing to search by Postcode. Screenshot here:
https://snipboard.io/jcx6VJ.jpg
Is there a way to change the query to search by that ACF field. For example, if I search for 3033 in the search field and click search I need it to show results that contain that postcode and not any of the titles etc.
Hoping someone can help me out.
Thanks so much,
DayneTrevor(Private) July 20, 2020 at 1:10 pm #253298If you were to use the Text search box to search that field, it would work.
Our plugin does not directly allow you to do text searches of individual Post Meta (custom fields) and Taxonomy (Category, Tags and Taxonomies) data/terms. The Search & Filter Pro Text Search field uses the standard WordPress search, so looks only in the Post Title and Content. To help you control this better, on the form’s Advanced settings tab you will see 2 settings for Relevanssi.
The documentation for this is here:
https://www.designsandcode.com/documentation/search-filter-pro/3rd-party/relevanssi/
You would need to install and activate the free Relevanssi plugin as well.
Then set Relevanssi up and build its index (make sure it is indexing the desired post types, custom fields AND any taxonomy that you want to search).
You can have only one Text search field per form, and one form per page. So, you can’t have multiple boxes to each search a different custom field.
-
AuthorPosts