Home › Forums › Add-ons › Flexible Content Field › get_sub_field returns bool (false)
hello,
I have a problem on my website, when I try to get the repeater subfield, the loop only finds the value of the first field which is a radio button, for the following ones I get nothing, and when I try to display these fields with the var_dump I find bool (false). this problem concerns only one repeater among the others.
My PHP version is 7.4
<?php
if ( have_rows('mb_hairstyle_tabs_repeater') ) :
$i = 0;
while ( have_rows('mb_hairstyle_tabs_repeater') ) : the_row();
$i++;
if (have_rows('mb_tab_products')) :
while ( have_rows('mb_tab_products') ) : the_row();
?>
<?php
$hairstyleTitle = get_sub_field('mb_hairstyle_title');
$hairstyleText = get_sub_field('mb_hairstyle_text');
$hairstyleImg = get_sub_field('mb_hairstyle_illustration');
$productTitle = get_sub_field('mb_product_title');
$productText = get_sub_field('mb_product_text');
$productImg = get_sub_field('mb_product_illustration');
$productBtnLabel = get_sub_field('mb_product_button_label');
$productExternalBtn = get_sub_field('mb_product_external_link');
$productImgSize = 'full';
$position = get_sub_field('mb_hairstyle_product_position');
endwhile;
endif;
endwhile;
endif;
?>
You cannot get sub fields of the first repeater inside of the nested repeater loop.
if (have_rows('repeater')) {
while (have_rows('repeater')) {
// you can access sub fields of "repeater" here
if (have_rows('nested_repeater) {
while (have_rows('nested_repeater) {
// you can access sub fields of nested repeater here
// you cannot access sub fields of "repeater" here
} // end while nested repeater
} // end if nested repeater
// you can access sub fields of "repeater" here
} // end while "repeater"
} // end if "repeater"
yes i am trying to get the subfields of the nested repeater, and when i try to get it by this method it returns the value:
get_field(‘mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_0_mb_hairstyle_title’);
Looking at the meta key you have
Where is the loop over “mb_collection_strates” being performed?
It is assigned in another file that calls this one :
if(have_rows('mb_collection_strates')):
while(have_rows('mb_collection_strates')): the_row();
$layout = get_row_layout();
echo clrz_get_template_part('collections-level-one', $layout);
endwhile;
endif;
NB : the second nested repeater loop call just the radio button mb_hairstyle_product_position and does find any other field
I don’t see where ‘mb_hairstyle_tabs_repeater’ is part of a layout. How are are you including the repeater in a layout? clone? What are the clone settings?
I have looked several times and I don’t see why the values would not be shown, unless the values to not exist. Can you confirm that the values are actually being saved in the database? After you edit the page where this is located are the values loaded into the fields to edit?
in my template page I have this loop:
<div class="row">
<?php
if(have_rows('mb_collection_strates')):
while(have_rows('mb_collection_strates')): the_row();
$layout = get_row_layout();
echo clrz_get_template_part('collections-level-one', $layout);
endwhile;
endif;
?>
</div>
which uses files one of them contains this code
<div class="strate-collection-hairstyle strate-collection-hairstyle--mobile margin-bottom-xl">
<div class="container-fluid">
<div class="row collection-hairstyle-container js-hairstyle-tabs tabs">
<div class="col-xs-12 col-xs-offset-2 js-tab-content">
<div class="row">
<?php
$i = 0;
$tabsRepeater = get_sub_field('mb_hairstyle_tabs_repeater');
$tabsList = '<div class="col-xs-12 col-xs-offset-2 tabs__list"><ul class="text-uppercase js-tabs">';
if ( have_rows('mb_hairstyle_tabs_repeater') ) :
while ( have_rows('mb_hairstyle_tabs_repeater') ) : the_row();
$i++;
$tabName = get_sub_field('mb_tab_name');
$tabTitle = get_sub_field('mb_tab_title');
$tabText = get_sub_field('mb_tab_text');
$tabImg = get_sub_field('mb_tab_illustration');
$tabBtnLabel = get_sub_field('mb_tab_button_label');
$tabBtnExternalTarget = get_sub_field('mb_tab_external_target');
$tabBtnUrl = get_sub_field('mb_tab_button_target_url');
// $tabInternalLink = get_sub_field('mb_tab_internal_link');
if ( $tabBtnExternalTarget ) :
$link = get_sub_field('mb_tab_button_target_url');
else:
$link = get_sub_field('mb_tab_internal_link');
endif;
// Récupération infos meta de la page cible (image pour Pinterest)
$subPageId = url_to_postid($link);
$seoOgDescription = $tabTitle . ' - ' . $tabText;
// priorité à l'image SEO Yoast
$seoOgImageUrl = get_post_meta($subPageId, "_yoast_wpseo_opengraph-image")[0];
if (!$seoOgImageUrl) { // Fall-back sur l'image de l'onglet
$seoOgImageUrl = clrz_get_image_url($tabImg, '625x880');
}
// TESTS
// var_dump(get_post_meta($subPageId));
// echo '<img src="' . $seoOgImageUrl . '" alt="bob" />';
// END TESTS
if ( $i == 1 ) :
$active = 'active';
else:
$active = '';
endif;
$tabsList .= '<li class="tabs__name text-uppercase js-tab js-tab-content '. $active .'" data-id="' . $i . '">' . $tabName . '</li>';
?>
<div class="col-xs-16 margin-bottom-md tabs__content js-tab-content <?php echo $active; ?>" data-id="<?php echo $i;?>">
<img />" alt="">
</div>
<div class="col-xs-16 tabs__content black js-tab-content <?php echo $active; ?>" data-id="<?php echo $i;?>">
<div class="content">
<div class="title-sub">
<p class="h2 black smooth-font"><?php echo $tabTitle ?></p>
</div>
<p class="tabs__content--text"><?php echo $tabText?></p>
<div class="tabs__content--footer clearfix">
<?php if ($tabBtnLabel) : ?>
<a>" class="text-uppercase button button--black" title="<?php echo $tabBtnLabel?>"><?php echo $tabBtnLabel?></a>
<?php endif; ?>
<ul class="socials margin-top-md">
<li class="button">
<a>" target="_blank" title="<?php echo __( 'Partager sur Facebook', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-facebook"></use>
</svg>
</a>
</li>
<li class="button">
<a>&media=<?php echo urlencode($seoOgImageUrl); ?>&description=<?php echo urlencode(strip_tags($seoOgDescription));?>" target="_blank" title="<?php echo __( 'Partager sur Pinterest', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-pinterest"></use>
</svg>
</a>
</li>
<li class="button">
<a>&text=<?php echo urlencode(strip_tags($seoOgDescription));?>" target="_blank" title="<?php echo __( 'Partager sur Twitter', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-twitter"></use>
</svg>
</a>
</li>
</ul>
</div>
</div>
</div>
<?php
endwhile;
endif;
?>
</div>
</div>
<?php
$tabsList .= '</ul></div>';
echo $tabsList;
?>
<!-- PRODUITS RELATIFS A L'ONGLET -->
<?php
if ( have_rows('mb_hairstyle_tabs_repeater') ) :
$i = 0;
$j = 0;
while ( have_rows('mb_hairstyle_tabs_repeater') ) : the_row();
$i++;
if (have_rows('mb_tab_products')) :
while ( have_rows('mb_tab_products') ) : the_row();
?>
<?php
// $hairstyleTitle = get_sub_field('mb_hairstyle_title');
// $hairstyleText = get_sub_field('mb_hairstyle_text');
// $hairstyleImg = get_sub_field('mb_hairstyle_illustration');
// var_dump(get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_0_mb_hairstyle_title'));
// $productTitle = get_sub_field('mb_product_title');
// $productText = get_sub_field('mb_product_text');
// $productImg = get_sub_field('mb_product_illustration');
// $productBtnLabel = get_sub_field('mb_product_button_label');
// $productExternalBtn = get_sub_field('mb_product_external_link');
$hairstyleTitle = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_hairstyle_title');
$hairstyleText = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_hairstyle_text');
$hairstyleImg = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_hairstyle_illustration');
$productTitle = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_title');
$productText = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_text');
$productImg = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_illustration');
$productBtnLabel = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_button_label');
$productExternalBtn = get_field('mb_collection_strates_3_mb_hairstyle_tabs_repeater_0_mb_tab_products_'.$j.'_mb_product_external_link');
$productImgSize = 'full';
$position = get_sub_field('mb_hairstyle_product_position');
$j++;
if ( $productExternalBtn ) :
$link = get_sub_field('mb_product_button_target_url');
else:
$link = get_sub_field('mb_product_internal_target');
endif;
if ($position == 'left') :
$class = '';
$content = 'col-xs-12 col-xs-offset-2';
$positionClass = 'strate-collection-product--left';
else:
$class = 'pull-right';
$content = '';
$positionClass = 'strate-collection-product--right';
endif;
if ($i == 1) :
$positionClass .= ' active';
endif;
?>
<div class="col-xs-16 strate-collection-product <?php echo $positionClass; ?> js-tab-content" data-id="<?php echo $i?>">
<div class="row">
<div class="col-xs-14 col-xs-offset-right-2 bg-black collection-product__hairstyle <?php echo $class; ?>">
<div class="row">
<div class="content <?php echo $content; ?> margin-top-xl">
<div class="title-sub margin-bottom-sm">
<span class="h2 white smooth-font"><?php echo $hairstyleTitle ?></span>
</div>
<p class="smooth-font white"><?php echo $hairstyleText;?></p>
</div>
<img />" alt="">
<ul class="socials <?php echo $content; ?> margin-bottom-md">
<li class="button">
<a>" target="_blank" title="<?php echo __( 'Partager sur Facebook', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-facebook"></use>
</svg>
</a>
</li>
<li class="button">
<a>&media=<?php echo urlencode(clrz_get_image_url($productImg, $productImgSize)); ?>&description=<?php echo $productTitle;?>" target="_blank" title="<?php echo __( 'Partager sur Pinterest', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-pinterest"></use>
</svg>
</a>
</li>
<li class="button">
<a>&text=<?php echo $productTitle;?>" target="_blank" title="<?php echo __( 'Partager sur Twitter', 'clrz_lang' ); ?>">
<svg class="icon">
<use xlink:href="#icon-twitter"></use>
</svg>
</a>
</li>
</ul>
</div>
</div>
<div class="col-xs-12 col-xs-offset-2 collection-product__product">
<?php if($productTitle == ""):?>
<?php /* nothing to do */ ?>
<?php else: ?>
<span class="h2 text-uppercase margin-bottom-lg"><?php echo $productTitle; ?></span>
<?php endif;?>
<div class="text-center">
<div class="margin-bottom-md h-auto row">
<img />" alt="">
</div>
<p class="margin-bottom-md wysiwyg"><?php echo $productText?></p>
<?php if($productBtnLabel == ""):?>
<?php /* nothing to do */ ?>
<?php else: ?>
<a>" class="text-uppercase button button--black" title="<?php echo $productBtnLabel;?>"><?php echo $productBtnLabel;?></a>
<?php endif; ?>
</div>
</div>
</div>
</div>
<?php
endwhile;
endif;
endwhile;
endif;
?>
</div>
</div>
</div>
When I modify the value of one of it’s field, and after modifying the page I still find the old value, also when create a new field and I try to fill it it always remains empty.
I think you are running into an issue with a php setting, possibly max_input_vars or max_input_nesting_level or maybe post_max_size. More than likely it is max_input_vars.
Hello,
I increased the quotas of the max_input_vars, max_input_nesting_level and post_max_size, but the problem persists.
is there another probable source of the problem?
Thank you,
Hello,
I increased the quotas of max_input_vars, max_input_nesting_level and post_max_size but the problem persists.
is there another probable source of the problem?
Thank you,
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 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.