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 🙂
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.