Home › Forums › Add-ons › Flexible Content Field › Programatically removing all flex layouts from a post › Reply To: Programatically removing all flex layouts from a post
So for brevity sake, I didn’t want to post every permutation of code that I tried. But taking a second look through them I realized I had some arguments out of order on one and it now seems to work. This will essentially “shift” the first layout (row?) off of the flex component:
delete_row('community_flex_components', 1, 999)
So given the warning about running delete_row()
inside of have_rows
loop, is the following an effective way to properly empty a flex component?
$length = count(get_field('community_flex_components', 999));
for ($i = 0; $i < $length; $i++) {
delete_row('community_flex_components', 1, 999);
}
It seems kind of ugly but I’m not immediately clear of any other way to do it. Appreciate any tips or insight.
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.