Home Forums ACF PRO Clear editor content depending on option


Clear editor content depending on option

  • 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?


  • 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
            } elseif( get_sub_field('content_type') == 'background' ) {
                // show background
    else :
        // no rows found

    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.

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Clear editor content depending on option’ is closed to new replies.