I have setup a page builder type repeater for my front page where a repeater is a section and the repeater’s subfields are various options for customizing the content and content type.
The problem lies where I have a dropdown options selection where you can select the content type (if it’s an article or background image, etc.), however, if I fill out the wysiwyg editor and then select a different option, say the background, it will then keep both. How can I clear the content in the editor if a different value is selected?
Thanks!

Hi @ophie
The repeater field will keep the subfields value until you deleted the value manually. That means using conditional logic won’t delete the value.
As a workaround, you need to check the select value and show the right layout for the right content type like this:
// check if the repeater field has rows of data
if( have_rows('repeater_field_name') ):
// loop through the rows of data
while ( have_rows('repeater_field_name') ) : the_row();
// check the content type
if( get_sub_field('content_type') == 'article' ) {
// show article
the_sub_field('article_sub_field_name');
} elseif( get_sub_field('content_type') == 'background' ) {
// show background
the_sub_field('background_sub_field_name');
}
endwhile;
else :
// no rows found
endif;
I hope this helps 🙂
Thanks James!
I realized that I wasn’t checking the value chosen in the select option at all. I only checked if the fields had content or not, thus when ACF saved both values it was also showing them and breaking the page. I made an assumption that the plugin takes care of that since I set up that conditional logic for the forms but there is no reason for it to do that.
Test and double test before going live, clients are really awful beta testers.
The topic ‘Clear editor content depending on option’ is closed to new replies.
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.