Home › Forums › Add-ons › Flexible Content Field › Need to short or write better my code. › Reply To: Need to short or write better my code.
There is likely a better way to do what you are trying to do, but I don’t understand the bigger picture so all I can do it to help you optimize the code that you’ve supplied. For this purpose I would use variable variables.
This code has not been tested
$content_rows = get_field(‘flexible_content’, ‘options’);
for ($i=0; $i<count($content_rows); $i++) {
$row_var = "content_specific_row_{$i};
${$row_var} = $content_rows[$i];
$content_var = "content_sub_field_value_{$i}";
${$content_var} = ${$row_var}['content'];
}
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!
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp
— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.