Support

Account

Home Forums Front-end Issues Search form using acf get all values

Unread

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'
                        )
                ),
               
            ),
        );
    };
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.