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!
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.