Home › Forums › Add-ons › Flexible Content Field › Getting flexible content sub_fields and making menu from them
Hello,
I want to catch all specific sub_fields from flexible content field and make the menu from them.
Here is the code for my flexible content field:
<?php
if( have_rows('modules') ): while ( have_rows('modules') ) : the_row();
if( get_row_layout() == 'photo' ):
the_sub_field('menu_name'));
the_sub_field('photo'));
elseif( get_row_layout() == 'text' ):
the_sub_field('menu_name'));
the_sub_field('text'));
<?php endif; endwhile; else : endif; ?>
I want to get all the_sub_field(‘menu_name’) and to populate menu from that, like this:
<ul>
<li>1st the_sub_field('menu_name'));</li>
<li>2st the_sub_field('menu_name'));</li>
<li>3st the_sub_field('menu_name'));</li>
<li>4st the_sub_field('menu_name'));</li>
<li>5st the_sub_field('menu_name'));</li>
</ul>
Any help on that?
Maybe something like:
<?php if( have_rows('modules') ): ?>
<?php $menu_items = ''; ?>
<?php while ( have_rows('modules') ) : the_row();
if( get_row_layout() == 'photo' ):
$menu_items .= '<li><img src="' . get_sub_field('photo') . '" alt="' . get_sub_field('menu_name') . '"><li>';
elseif( get_row_layout() == 'text' ):
$menu_items .= '<li>' . get_sub_field('menu_name') . ' ' . get_sub_field('text') . '</li>';
<?php endif; endwhile; ?>
<ul>
<?php echo $menu_items; ?>
</ul>
<?php endif; // end modules has rows ?>
Yeahhhh π Actually it’s pretty simple solution. Just using the same source code and making output of only menu item sub_field, ignoring all other fields.
Thanks ractoon for your help. I will try it and come back if its solved π
My final code for this issue:
<?php if( have_rows('modules') ): ?>
<ul>
<?php while ( have_rows('modules') ) : the_row();
if( get_row_layout() == 'photo' ):
echo '<li>'.the_sub_field('menu_name') . '<li>';
elseif( get_row_layout() == 'text' ):
echo '<li>' . the_sub_field('menu_name') .'</li>';
endif; endwhile; ?>
</ul>
<?php endif; // end modules has rows ?>
It works perfectly. Thanks ractoon for your help. It was more easier when i was trying to do it π
You must be logged in to reply to this topic.
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βre reaching out to our multilingual users to ask for help in translating ACF 6.1. Help make sure the latest features are available in your language here: https://t.co/TkEc2Exd6U
— Advanced Custom Fields (@wp_acf) May 22, 2023
© 2023 Advanced Custom Fields.
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.