Hello
I’ve created a few CPTs and custom fields that go with the CPTs – my main concern is now how to have them searched when a user searches a certain term and how to present the search results incl. the custom field values.
can anyone please point me into the right direction?
Thank you
Hi @mmjaeger
You could give this plugin a try: https://wordpress.org/plugins/search-everything/. I basically extends WP search functionality to include also the custom fields.
Alternatively, you could hook a function to pre_get_posts
action hook. In your function, first verify whether you are in the search page, if so, then proceed to create a meta query using the search input. Here are link to resources which will help you achieve this:
https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
https://codex.wordpress.org/Class_Reference/WP_Meta_Query
Hope this helps 🙂