Using meta_query with ACF repeater field

Trying to loop through an ACF repeater field using a meta_query, inside the WP_Query? All you need is a function to replace the way the meta_key works.

ACF repeater within the meta_query

In order to use the repeater field within the loop’s meta_query, you need to paste the code below inside your functions.php file accordingly.

function wpza_replace_repeater_field( $where ) {
     $where = str_replace( "meta_key = 'repeaterkey_$", "meta_key LIKE 'repeaterkey_%", $where );
     return $where;
}
add_filter( 'posts_where', 'wpza_replace_repeater_field' );

Once you’ve done this, within your WP_Query‘s arguments, you should use the meta_query parameter as such:

$args = array(
     'post_type' => 'posttype',
     'meta_query' => array(
          array(
               'key' => 'repeaterkey_$_repeateritemkey',
               'value' => 1,
               'compare' => '='
          )
     )
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
     // Do loop content
endwhile;
wp_reset_postdata();