Home › Forums › Front-end Issues › Search form using acf get all values
Hey all,
I built a search form using acf fields and I have problems.
The issue is as so: I have a select field in the site frontend, the select is an acf field That I want to filter by.
What I want to do is to receive all the values of the field when I select the all rooms
option that added manually.
I read theis post and I think that the question is simillar.
https://support.advancedcustomfields.com/forums/topic/filter-post-by-query-if-the-value-is-null/
select retreive code:
<div>
<?php
$rooms_field_key = "field_59ae9e2370a0b"; //prop_rooms
$rooms_field = get_field_object($rooms_field_key);
if( $type_field )
{
echo '<select name="' . $rooms_field['key'] . '">';
?>
<option value="">all rooms</options>
<?php
foreach( $rooms_field['choices'] as $k => $v )
{
echo '<option value="' . $k . '">' . $v . '</option>';
}
echo '</select>';
}
?>
</div>
This is the args var in search.php page:
if (isset($_GET['front-side-prop-search'])){
$args = array(
'posts_per_page' => 9,
'post_type' => 'property',
'meta_query' => array(
'relation ' => 'AND',
array(
'key' => 'prop_city',
'value' => $city,
'compare' => '=',
'relation' => 'OR',
array(
'key' => 'prop_city',
'compare' => 'NOT EXISTS'
)
),
array(
'key' => 'prop_rooms',
'value' => $rooms,
'compare' => '=',
'relation' => 'OR',
array(
'key' => 'prop_type',
'compare' => 'NOT EXISTS'
)
),
),
);
};
The topic ‘Search form using acf get all values’ is closed to new replies.
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.