Home › Forums › General Issues › Flexible content Inception › Reply To: Flexible content Inception
Update. I know where/when the infinite loop occurs.
Now, I need to find how to solve it (and I’ve not yet found).
Here’s an extract of my code:
function taz_get_field_data($shortcodeID){
if (class_exists('acf')){
$layouts = get_field('taz_features', false, true);
return $layouts[$shortcodeID - 1];
} else {
error_log("taz_get_field_data(): ACF Plugin is not available.");
return null;
}
}
function taz_features($atts, $content = null){
$a = shortcode_atts(array(
'id' => null
), $atts);
$shortcodeID = (int)$a['id'];
$rowData = taz_get_field_data($shortcodeID);
switch ($rowData['acf_fc_layout']){
case 'gallery':
[…]
break;
case 'carousel':
[…]
break;
[…]
}
}
add_shortcode('taz_features', 'taz_features');
Line 3 of the above code, we have: $layouts = get_field(‘taz_features’, false, true);
When the last parameter is set to true, looks like the shortcode [taz_features id=4] is executed, thus entering again my shortcode function (taz_features), which will run taz_get_field_data(), which run get_field() again, and so on, thus generating the loop 🙁
Setting false to the format value could solve my problem, but it would imply massive modifications of the rest of my code. I’d definitely like to avoid this.
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.