Support

Account

Home Forums General Issues Flush Unused Custom Fields Reply To: Flush Unused Custom Fields

  • Every field does have a unique identifier, it’s called the field key.

    The problem is that ACF does not know that a field has been deleted or what data should be deleted. When you update a field group ACF has the submitted data to work with. Since the deleted field in the group is not submitted there is no immediate way to know that anything was removed. This might be possible to do by comparing the old values with the new values. This would be an extremely complex issues due to repeaters, flex fields, clones and the like and the complicated way these fields can be nested.

    The second problem is efficiency. Let say that you have a really large site of 10,000 posts. ACF works within the confines of WP, using nothing by WP functions and filters. It does nothing that we cannot do on our own using standard WP function. Taking this into account, ACF would need to do a query for every post on the site, loop though them and use the WP function to delete the meta value for each post 1 at a time, and it would need to do this for every field that was deleted. Doing this on more than a few posts would time out the process. This would also need to be done based on field nesting of things like repeaters, making it more complex to do that just calling the delete function. Could this be done faster, yes, by doing queries on the database directly, but this is not something the can be done with existing WP functions and filters.

    Let’s look at this second method of querying the database directly. You could do a query of the meta field values for all rows matching the field key. This would get a list of all of the field names matching that field key. You can then do a delete query to delete anything that matches that field name. The problem here is that you could have 2 fields with the same name. Even using queries directly on the database it would be impossible to discern the difference between these fields. If you have 2 fields of the same name you will delete the data for both of them. This is mainly an issue with the way that WP’s database is created. There isn’t a way to relate 1 row in the meta table with another.

    Anything that changes the way that ACF stores the value would change the way it works. One of the developers goals is also to make it possible for you to use standard WP functions, like get_post_meta() to get values and not to need to depend on get_field() if you want to remove ACF for some reason. Any complex way of storing data make you dependent on ACF rather that it being a big container for the things that can be done with WP without ACF.

    I’m not the developer, and I don’t know if he will ever be able to do these things, but the problem is far more complex than it may appear.