Support

Account

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).")";
    
    ?>