Support

Account

Home Forums Backend Issues (wp-admin) How do I clean up old ACF fields in DB? Reply To: How do I clean up old ACF fields in DB?

  • I’m not entirely sure this would work, however, if someone is adventurous and has some time to kill they could. This is just a general outline.

    Create an acf/save_post function.

    In this function get all of the postmeta fields in the database for the post. You’d want to specifically get all fields with a value like ‘field_%’. The meta_key values of these fields in the database are you field name pre_pended with an underscore.

    You could then loop through all of the posted data that is posted using the acf field key values (‘field_%’) and compare them to the list of fields that you collected in the first step, removing from your list anything that’s being submitted. This would be the hard part because the posted data will be a complex nested array.

    What you should have left is a list of fields that are no longer used.

    loop trough the this list and delete all of the unused fields ‘MY_FIELD’ & ‘_MY_FIELD’ using delete_post_met();

    If you could get it to work it might be a useful for others.