I did not find on your site and on google, the case of a flexible content inside a repeater.
Unfortunately I can not recall correctly a flexible content that is filed inside a repeatable.
A normal field flexibile activates a great time with foolish examples.
flex_content = field type flex content
1° element on flex content = flex_content_first_element
sub field in to 1° element = flex_content_first_element_subfield
2° element on flex content = flex_content_second_element
sub field in to 2° element = flex_content_second_element_subfield
if( have_rows('flex_content') ){
// loop through the rows of data
while ( have_rows('flex_content') ){ the_row();
if( get_row_layout() == 'flex_content_first_element' ){
the_sub_field('flex_content_first_element_subfield');
}
elseif( get_row_layout() == 'flex_content_second_element' ){
the_sub_field('flex_content_second_element_subfield');
}
}
} else { }
so everything is right. But if the value “field type flex content” was not top level but it is contained by a field riptetitore.
What should I put in “have_rows (?)”
I tried several attempts but do not function.
So, you are the ultma beach ..
I hope you know tell me the right one variable for this to work.
Thank you!
You need to have nested loops for flex fields inside a repeater
if (have_rows('repeater_field')) {
while (have_rows('repeater_field')) {
the_row();
if (have_rows('flex_content_field')) {
while (have_rows('flex_content_field')) {
$layout = get_row_layout();
// and the rest of your flex field output
} // end second while have rows
} // end second if have rows
} // end first while have rows
} // end first if have rows
for more information see the nested loop section of this page http://www.advancedcustomfields.com/resources/have_rows/
thanks, now I understand the concept of recall.
I had not thought because I usually use the foreach statement to retrieve reperater.
I looked back and saw that I forgot something important. My code above will create and infinite loop. Someday I should right a book on how to do it 😛
if (have_rows('repeater_field')) {
while (have_rows('repeater_field')) {
the_row();
if (have_rows('flex_content_field')) {
while (have_rows('flex_content_field')) {
the_row(); // forgot this line
$layout = get_row_layout();
// and the rest of your flex field output
} // end second while have rows
} // end second if have rows
} // end first while have rows
} // end first if have rows
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!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 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.