Support

Account

Home Forums Add-ons Repeater Field Using get_post_meta as Fallback on Repeaters Reply To: Using get_post_meta as Fallback on Repeaters

  • because $rows always have the count of rows you could use:

    $rows = get_post_meta( 348, 'testimonials', false ); // get number of rows (8 but in a array)
    $row_count = $rows[0]; //get row number out of array (8)
    $row_count--; // because first row start with 0 not 1 subtract one from row number (8-1 =7)
    //now you could use $row_count to get last row (7)
    echo 'testimonials_'.$row_count.'_testimonial'; //you need to replace echo by a variable and use that

    Hint:
    $rows--; is short form of $rows = $rows-1;
    because $rows and better $row_count always have the correct row number you can add/remove rows without problems