I am trying to get a field from a flexible content.
I want to get the field area_name
from area_flex
and print it in the paragraph
section
This is the code below:
<?php if( have_rows('flexible_content') ):
while ( have_rows('flexible_content') ) : the_row();
if( get_row_layout() == 'paragraph' ): ?>
<?php if( get_row_layout() == 'area_flex' ): ?>
<a href="<?php the_sub_field('area_name', 3142); ?>"></a> //Paste here
<?php endif; ?>
<?php elseif( get_row_layout() == 'area_flex' ): ?>
<button class="accordion"><?php the_sub_field('area_name'); ?></button> //Get field from here
<?php endif;
endwhile;
endif; ?>
You have two checks on the layout nested. The layout can’t be “paragraph” and at the same time be “area_flex”
And is there a way to get the field area_name
from area_flex
and print it in the paragraph
section?
No, using the ACF have_rows() loop you can’t get fields from a different row, only from the current row.