Support

Account

Home Forums Front-end Issues ACF Search in Post Object Reply To: ACF Search in Post Object

  • I have been changed post_object to the Relationship and have one problem.
    When I load category all information load good, but when I trying to search I have disappeared one field (the second field send me empty array ). Where is have a mistake?

    Function for filter

    <?php
    function go_filter()
    {
        $_name = $_GET['tournament_name'] != '' ? $_GET['tournament_name'] : '';
        $args = array(
            'post_type' => 'events', // your CPT
            's' => $_name
        );
        $args['meta_query'] = array('relation' => 'AND');
        global $wp_query;
    
        if ($_GET['team_1'] != '') {
            $args['meta_query'][] = array(
                'key' => 'filter_team_1',
                'value' => $_GET['team_1'],
            );
        }
        if ($_GET['team_2'] != '') {
            $args['meta_query'][] = array(
                'key' => 'filter_team_2',
                'value' => $_GET['team_2'],
            );
        }
        query_posts(array_merge($args, $wp_query->query));
    }
    
    ?>

    And page content

    <?php if ($_GET && !empty($_GET)) {
                                go_filter();
    
                            } ?>
                            <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
                                <?php $team_1 = get_field('team_1'); ?>
                                <?php $team_2 = get_field('team_2'); ?>
                                <li>
                                    <div class="team">
                                        <?php echo get_the_post_thumbnail($team_1[0]); ?>
                                        <?php echo get_the_title($team_1[0]); ?>
                                    </div>
                                    <div class="separate">VS</div>
                                    <div class="team">
                                        <?php echo get_the_post_thumbnail($team_2[0]); ?>
                                        <?php echo get_the_title($team_2[0]); ?>
                                    </div>
                                    <div class="time"><?php the_field('game_time'); ?></div>
                                    <a href="<?php the_field('game_link'); ?>">Tournament</a>
                                </li>
                            <?php endwhile;
                            else : ; ?>
                                <h4>Sorry, nothing matched your search criteria!</h4>
                            <?php endif; ?>
    
                            <?php wp_reset_query(); ?>