Home › Forums › Add-ons › Flexible Content Field › How to get label for › Reply To: How to get label for
Thank you for the reply and sorry for the delay in answering. Nevermind the properties (like key) of the layout object look different, the idea of looping through the subarray was indeed what did the trick. With help from a friend who’s a PHP veteran, the following loop gave the wanted values.
To loop through all items at once:
<?php
foreach($content['layouts'] as $layout) {
echo 'layout: ' . $layout['label'] . '<br>';
foreach($layout['sub_fields'] as $subField) {
echo 'field: ' . $subField['label'] . '<br>';
}
}
?>
To put the item on the right spot, it’s necessary to point to the right index-number of the subarray.
So for example (using the loop from the question), this worked for Highlights with index 1:
<?php elseif(get_row_layout() == "highlights"): ?>
<?php echo $content['layouts'][1]['sub_fields'][0]['label']; //highlights ?>
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.