Home Forums General Issues ACF field not deleted on page save Reply To: ACF field not deleted on page save

  • This question actually comes up quite often.

    ACF has never removed values that are no longer used and it has always been the case that we must implement our own logic to decide if we should get a field or not get a field. The same is true of conditional logic. Let’s say that you have a true false field and two fields based on if this field is checked or not. In your template you must check this field to see if it’s true or false because both of the fields might contain a value.

    I your case, since sub pages will not have this menu field, the first thing you should be checking is if the page is a child of another page.

    if ($post->parent != 0) {
      // this is a child page.

    The issue is a deep one, ACF does not know when saving a post, what fields are included and what fields are not. Really the point is that ACF does not know, and cannot figure out what fields exist that might need to be deleted or removed. There isn’t a way to get a list of all field and groups that ARE NOT included for a location. The only thing it has to go by is what is submitted and what fields ARE included for a location.

    If it is necessary to make sure that values are removed when no longer needed then what we need to do is create an acf/save_post filter and do this checking ourselves and delete what we don’t want any more.

    This is the same way the WP works. If you created your own custom fields not using ACF, then you removed the meta boxes from the admin interface for those fields all of that data would still exist in the database. If you use a particular theme that creates custom fields and then switch themes, more than likely any content in those custom fields will still exist if you decide to switch themes.