Support

Account

Home Forums Add-ons Repeater Field Query repeater field with two values Reply To: Query repeater field with two values

  • I have this code example for a project if it helps (it’s not WP_Query but get_posts, seance is my custom post type, seances a repeater field and film is a relationship field) :

    <?php 
                            $today = date("Ymd");
                            $date = strtotime($today);
                            $seances = get_posts(array(
                                'suppress_filters' => FALSE,
                                'post_type' => 'seance',
                                'meta_key'  => 'date',
                                'orderby'   => 'meta_value_num',
                                'order'=>'ASC',
                                'meta_query' => array(
                                    'relation'      => 'AND',
                                    array(
                                        'key' => 'seances_%_film', // name of custom field
                                        'value' => '"' . get_the_ID() . '"', // matches exaclty "123", not just 123. This prevents a match for "1234"
                                        'compare' => 'LIKE'
                                        ),
                                     array(
                                        'key'       => 'date',
                                        'compare'   => '>=',
                                        'value'     => $today,
                                    )
                                    )
                                ));
                        ?>

    And in functions.php

    function my_posts_where( $where ) {
        global $wpdb;
        $where = str_replace(
                  "meta_key = 'seances_", 
                  "meta_key LIKE 'seances_",
                  $wpdb->remove_placeholder_escape($where)
        );
        return $where;
    }
     
    add_filter('posts_where', 'my_posts_where');