Query by 2 values of a repeater ACF field

I know this is an old question, but I thought I’d post the answer in case anybody else is facing the same problem.

functions.php:

    function add_cond_to_where( $where ) {

        //Replace showings_$ with repeater_slug_$
        $where = str_replace("meta_key = 'showings_$", "meta_key LIKE 'showings_%", $where);

        return $where;
    }

add_filter('posts_where', 'add_cond_to_where');

Query:

//Replace showings_$ with repeater_slug_$
//Replace _discounts with _sub_element_slug
    $args = array(
        'meta_query'        => array(
            array(
                'key'       => 'showings_$_discount',
                'value'     => 'students',
                'compare'   => '='
            )
        )
    );

Reference: https://www.advancedcustomfields.com/resources/query-posts-custom-fields

I hope this helps,

Cheers!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)