Home Forums ACF PRO How to get repeater data for SQL query?


How to get repeater data for SQL query?

  • I have a repeater field setup for a CPT, Field name is “Zip Codes” and the sub field is “Zip Code”.

    I am trying to use those fields as part of an SQL query where I can search if any of the entered zip codes matches a search criteria.

    Anyone know how to grab and iterate over repeater fields in the database?


  • You could iterate over the repeater field adding the values to an array, then use that array to make the sql statement.


    $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');
    else :
        // no rows found
    $sql = "SELECT * FROM table_name WHERE field_name IN (".implode(",",$my_sql).")";
Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘How to get repeater data for SQL query?’ is closed to new replies.