Loop in an ACF Repeater field with Meta_query
Add this code in your plugin or function file:
<?php
// Query in ACF repeater
add_filter( 'posts_where', 'wpster_replace_repeater_field' );
function wpster_replace_repeater_field( $where ) {
$where = str_replace( "meta_key = 'repeater_key_$", "meta_key LIKE 'repeater_key_%", $where );
return $where;
}
?>
And in your WP_Query, use the meta_query parameter:
<?php
$args = array(
'post_type' => 'post_type_name',
'meta_query' => array(
array(
'key' => 'repeater_key_$_repeater_sub_key',
'value' => 1,
'compare' => '='
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
// your loop content
endwhile;
wp_reset_postdata();
?>