Hi – I’ve successfully outputted the contents of a multiple select field on my web page using following code in page template:
if( have_rows('flexible_content_field_name') ):
while ( have_rows('flexible_content_field_name') ) : the_row();
if( get_row_layout() == 'likes' ):
$likes_list = get_sub_field('likes_list');
echo implode(', ', $likes_list);
endif;
endwhile;
endif;
Page output is : item1, item2, item3
I’d like to break up the implode(', ', $likes_list);
code so that I can make my the items output into an unordered list:
Any help much appreciated!
Hi @nadgemanforum
It’s just a matter of looping through the values (it’s an array) and output an li
for each!
This should do it:
if( have_rows('flexible_content_field_name') ):
while ( have_rows('flexible_content_field_name') ) : the_row();
if( get_row_layout() == 'likes' ):
$likes_list = get_sub_field('likes_list');
if( $likes_list ):
echo '<ul>';
foreach( $likes_list as $like ):
echo '<li>' . $like . '</li>';
endforeach;
echo '</ul>';
endif;
echo implode(', ', $likes_list);
endif;
endwhile;
endif;
Best of luck in your project!
Thanks for your help Jonathan.
Just one thing: “echo implode(‘, ‘, $likes_list);” no longer required!
Thanks again.
@nadgemanforum
Lol.. I copied your code and forgot to delete it 😉
Anyway, you’re welcome! If you have more questions regarding ACF feel free to write in the forums.
How can I create a bullet list without having to code? I’m new to ACF and using CPT UI to set things up.