Home › Forums › ACF PRO › Search form with meta_field › Reply To: Search form with meta_field
Hi @beee
I think your approach is the best method for this situation. You can also use the $_POST
variable to get the field you want to search. So, you should be able to do it like this:
<input type="hidden" name="custom_field" value="field_name" />
And modify the query like this:
if( isset($_POST['custom_field']) ){
// set the meta query for your specific field
$query->set( 'meta_query', array(
'key' => $_POST['custom_field'],
'value' => $query->query['s']
) );
}
I hope this makes sense 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.