Home › Forums › ACF PRO › How to get repeater data for SQL query? › Reply To: How to get repeater data for SQL query?
You could iterate over the repeater field adding the values to an array, then use that array to make the sql statement.
Like:
<?php
$my_sql = array();
// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):
// loop through the rows of data
while ( have_rows('repeater_field_name') ) : the_row();
//add value to sql array
array_push($my_sql, get_sub_field('zip_code');
endwhile;
else :
// no rows found
endif;
$sql = "SELECT * FROM table_name WHERE field_name IN (".implode(",",$my_sql).")";
?>
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.