Home Forums General Issues Flush Unused Custom Fields


Flush Unused Custom Fields

    • zaccety

    • September 26, 2018 at 9:47 pm


    • horace

    • January 20, 2019 at 1:09 am

    recently i also came across this problem. i don’t mind the unused data per se but that it turns up in search results is a bummer. a lot of wordpress sites seem to suffer from this since i find a lot of weird search results on various wordpress sites i experimented with. πŸ™‚

    what is the current status of this and the cleanup plugins that some users did?

    wouldn’t a simple solution be to just delete all custom fields of a post on save_post (priority 1) and acf will store the currently used ones again afterwards anyway? a batch job could walk through all posts and resave them.

    someone mentioned a potential issue with clone fields but i never used them and don’t even know what they are. πŸ™‚

  • This is a pretty heavy-handed ‘solution’ but, for what it’s worth, what I’m doing at the moment to remove unused ACF post_meta data is this…

    I name all my ACF fields with a unique prefix (eg. my_prefix_first_name, my_prefix_last_name, etc…) making sure that my_prefix is unlikely to conflict with any default WordPress post_meta keys or any of the post_meta keys created by plugins that I might use.

    Then, every time I update a post, I simply delete ALL post_meta containing my_prefix using the acf/save_post action below:

    function acf_delete_all_post_meta($post_id) {
        global $wpdb;
        $result = $wpdb->query($wpdb->prepare("
            DELETE FROM wp_postmeta
            WHERE meta_key
            LIKE '%my_prefix%'
            AND wp_postmeta.post_id = %s",
    add_action('acf/save_post', 'acf_delete_all_post_meta', 1);

    With a priority of less than 10, this action will fire BEFORE the actual post data is saved. Thus, when the post data IS saved, it’s saved to a clean slate and only saves post_meta for fields that are currently being used in the post.

    Obviously, this technique will not flush your entire site of unwanted post_meta in one go – it only acts upon one post at a time and only when you update the post. However, if used during development (which is probably the only time I would use it) it will help tidy-things-up as you go along.

  • How would you modify this function for a multi-site? I do know the Site ID and the site-specific tables in which I want to delete left over acf meta data

  • +1

    No one likes a mess. And unless you get it right the first time (who does that?) you get a mess. A big messy mess. Seems like enough folks want this. Lot’s of paying custys. Put this at top priority finally after all these years.

    For anyone still interested, HookTurn has an awesome plugin that totally reworks how ACF stores data. Makes cleanup a breeze but the plugin is pricey!

    • sherman

    • September 13, 2019 at 6:18 am


    • rotome

    • October 3, 2019 at 5:17 pm


    We are still waiting. It’s been 5 years since the functionality request 🀦,


  • +1

  • +1

    All I need is a tool to delete orphaned ACF meta data. When you’re creating a site you frequently rename fields that have data already. It would be nice to just have a button that removes ACF meta data that’s no longer part of a field group.

Viewing 9 posts - 76 through 84 (of 84 total)

You must be logged in to reply to this topic.

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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.