Home › Forums › General Issues › Search form to query multiple acf fields › Reply To: Search form to query multiple acf fields
Hi @skellytig
You can use a plugin like the one @kolhoffmmm suggested. If you want to do it yourself the best way to do it would be to create your own form which would send to the same page (archive) using POST.
Then you hook into the pre_get_posts
filter: https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts
There you look for the values of your filter and modify the query accordingly.
Incomplete example:
$meta_query = array();
if( isset($_POST['filtervalue']) && $_POST['filtervalue'] ){
$meta_query[] = array(
'key' => 'filtervalue',
'value' => $_POST['filtervalue'],
'compare' => '='
);
}
if( isset($_POST['anotherfiltervalue']) && $_POST['anotherfiltervalue'] ){
$meta_query[] = array(
'key' => 'anotherfiltervalue',
'value' => $_POST['anotherfiltervalue'],
'compare' => '='
);
}
$query->set('meta_query', $meta_query);
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.