Home › Forums › Add-ons › Flexible Content Field › flexible content inside flexible content
Hi,
i’m trying to use flx content inside flx content.
my loop identify the different layouts but does not display the fields within the inner flx content.
this is my code:
<?php
if (get_field('form layouts')) {
while (has_sub_field('form layouts')) {
if (get_row_layout() == "flx_right_img") {
$right_image = get_sub_field('right_mian_img');
?>
<section id="wrapper">
<div id="main-content" class="row">
<div class="topHeader col web-100 tablet-100 mobile-100" style="background-color: <?php the_sub_field('right_bacjground_color_head'); ?>">
<div id="Asighnment"><?php the_sub_field('right_head'); ?></div>
</div>
<div class="col web-100" ></div>
<div id="right-bg" class="col web-66 tablet-100 mobile-100" >
<div class="imgWrp">
<img src="<?php echo $right_image['url']; ?>" alt=""/>
</div>
</div>
<div id="form3" class="col web-33 tablet-100 mobile-100">
<div id="form-body" class="fields-wrp">
<?php
if (get_sub_field('right_flx_inputs')){
while (has_sub_field('right_flx_inputs')){
if (get_row_layout() == 'flx_text'){
echo '<div class="field-holder">
<label>' . the_sub_field('text_lable') . '</label>
<div class="input-holder">
<input data-form-id="form3" data-msglbl="' . the_sub_field('text_id') . '" data-defmsg="' . the_sub_field('err_msg') . '" class="req" type="text" name="' . the_sub_field('text_name') . '" placeholder="' . the_sub_field('text_placeholder') . '" />
<label id="' . the_sub_field('text_id') . '" class="errorMsgLbl errorMsgText"></label>
</div>
</div>';
}
elseif (get_row_layout() == 'flx_textarea'){
echo '<div class="field-holder">
<label>' . the_sub_field('textarea_lable') . '</label>
<div class="input-holder">
<textarea data-form-id="form3" data-msglbl="' . the_sub_field('textarae_id') . '" data-defmsg="' . the_sub_field('textarea_err_msg') . '" class="req" type="text" name="' . the_sub_field('textarea_name') . '" placeholder="' . the_sub_field('textarea_placeholder') . '" ></textarea>
<label id="' . the_sub_field('textarea_id') . '" class="errorMsgLbl errorMsgText"></label>
</div>
</div>';
}
}
}
} ?>
</div>
</div>
</div>
</section>
<?php }
}
} ?>
thanks
The function you’re using has_sub_field()
is outdated and does not work well with nested flex fields as noted on this page https://www.advancedcustomfields.com/resources/has_sub_field/.
You should be using have_rows()
which is documented here https://www.advancedcustomfields.com/resources/have_rows/
The topic ‘flexible content inside flexible content’ is closed to new replies.
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.