1. MarcusPublished: 3 years ago


    I tried to put it in functions but got a blank screen for the webpage.

    What might I have done wrong? Is it outdated?

    You are right! This is exactly what I have been looking for!

    Is there something I could do to remove them by phpMyadmin by query instead of php. I have 500 000 rows…

    Thanks for the post!

    • IftekharPublished: 3 years ago

      Marcus, the only problem I see here is the name of my function (delete_post_meta) itself. I figured, that it is also the name of a native WP function. Perhaps, that could be an issue. However, I updated the snippet with new function name and changed it to “delete_useless_post_meta”. Also, please remember that you shouldn’t use “<?php” and “?>” tag while copying this snippet on your theme’s functions.php page. Can you try with this new snippet and let me know? Thanks.

  2. MarcusPublished: 3 years ago

    Thank you so much!

    It works great now! i am adding all kinds of stuff for it to delete.

    Is there a way to see which meta_key there is most rows of?

    I see that some have values, but I dont know if I need them i.e:

    – _downloadable (no) – I don’t have downloadable products
    – _virtual (no) – I am not using virtual products
    – _stock_status (yes) – I do not use stock at all cus we do drop shipping

    Are they safe to take away?

    Thank you!

    • IftekharPublished: 3 years ago

      It seems like you are using some sort of eCommerce plugin (WooCommerce most probably). In that case, I won’t recommend you to delete them. They are used and most probably required to store product meta data. If you really want to delete them, please do it at your own risk. You can use my function regardless to delete any meta key and their value. Hope that helps 🙂

      • MarcusPublished: 3 years ago

        Great Answer,

        Thanks a lot!

  3. Dipika DubeyPublished: 3 years ago

    Thanks a lot……explained very well .

    • IftekharPublished: 3 years ago

      You are welcome Dipika, I am glad that it was helpful for you 🙂

  4. DavidPublished: 1 year ago

    This is very helpful! Thank you for sharing.

    • IftekharPublished: 1 year ago

      Hello David, I am happy to know that you find this snippet to be useful. You are welcome and thank you for stopping by.

  5. AnnPublished: 11 months ago

    Forgive my complete ignorance, but if I add this to my child theme’s functions.php, will I still see post meta data on my wordpress posts? Thank you!

    • IftekharPublished: 11 months ago

      Dear Ann, I never tested this code on any “child theme”. However, I don’t see any reason why it won’t work. Then again I would highly recommend you to use this on the “parent theme” if you can. As far as post “meta data” is concern, this code will delete only few meta data (defined by meta key i.e. ‘_edit_last’) and rest (if there is any) should remain as it is. Hope that helps. Thank you.

  6. DeePublished: 10 months ago

    rare sharing indeed. thanks

    • IftekharPublished: 10 months ago

      You are welcome 🙂

  7. NataliiaPublished: 7 months ago

    Unfortunately, this code didn’t delete _edit_lock and _edit_last on my site.
    Maybe my table name, for example, “tablepostmeta”, withot “_” ?
    And do I need change wp_logout to myprefix_logout?

    Thank you!

    • IftekharPublished: 7 months ago

      Hello Nataliia, It really does not matter what “prefix” you have on your database table name. Because I used

      $table = $wpdb->prefix.'postmeta';

      on my function to deal with this issue. It will automatically grab your table’s prefix and delete the values of the specified meta key. These meta keys gets deleted as you log out from the system. You can check them from PhpMyAdmin as you log out. However, they gets created once again as you edit any post but like always, it gets deleted as you log out. It’s a continuous process. Hope that helps. Thank you.

Leave a Reply

Note: Convet HTML, PHP, JavaScripts from Postable, before posting from comment section.
License: By submitting a comment here you grant this site a perpetual license to reproduce your words and name/Web site in attribution. Please use your real name or a pseudonym (i.e., pen name, alias, nom de plume) when commenting. If you add your site name, company name, or something completely random, I'll likely change it to whatever I want.