How to use ACF repeater field with meta_query?

Hello there! Welcome back to another TechSolutionsHere article. In this article, I will show you how to use ACF repeater field with meta_query.

Let’s get started!

You need to add the following code into the theme/plugin functions.php/plugin-name.php file:

function tsh_replace_repeater_field( $where ) {
     $where = str_replace( "meta_key = 'yourrepeaterkey_$", "meta_key LIKE 'yourrepeaterkey_%", $where );
     return $where;
add_filter( 'posts_where', 'tsh_replace_repeater_field' );

Then go to your WP_Query’s arguments and use the meta_query parameter following:

$args = array(
     'post_type' => 'posttype', // your post type name here
     'meta_query' => array(
               'key' => 'yourrepeaterkey_$_repeateritemkey',
               'value' => 1,
               'compare' => '='
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
     // Do loop content

That’s it

If you have any queries then please let me know in the comments section. If you think this post has saved your time, please subscribe to our newsletter for regular updates.

Happy coding.

Thank you in advance!

Exit mobile version