Support

Account

Home Forums ACF PRO Get last row from a flexible content and display it on another page Reply To: Get last row from a flexible content and display it on another page

  • Hi @simtwo

    I believe you can check the total rows by using the count() function and then check if the current row is the last row by using the get_row_index() function. Maybe something like this:

    $total_rows = count(get_field( 'selection' ));
    // check if the flexible content field has rows of data
    if( have_rows('selection') ):
    
         // loop through the rows of data
        while ( have_rows('selection') ) : the_row();
    
            if( get_row_index() == $total_rows ) {
                echo "show the last row here";
            }
    
        endwhile;
    
    else :
    
        // else
    
    endif;

    I hope this helps 🙂