Home Forums General Issues Empty fields on wp_postmeta


Empty fields on wp_postmeta

  • I’ve 2 custom fields for each post.
    Some times I do not insert nothing inside the custom fields.
    So on the “wp_postmeta” db table I have a lot of rows with the empty “meta_value”

    1- Is it interesting to delete this rows?
    2- is it affecting to the performance of the database? (I have a lot of post)
    3- Is there a way to not create this row when the field is empty?
    4- Is any problem deleting this rows? Do you have an sql query to delete the empty rows from php my admin?

  • Hi @susa38

    Yes, it’s OK for you to delete it. ACF creates them to prepare the database when you need to update them.

    It shouldn’t affect your database performance much. But if you have an issue with your site performance, I suggest you use a caching plugin instead.

    Yes, you can manually delete the empty database row every time a post is saved, but it will cost more queries and will affect your site performance.

    I believe there won’t be any problem if you want to delete them. You can try the following SQL code, but please backup your site and database first.

    DELETE FROM wp_postmeta WHERE wp_postmeta.meta_value = ''

    Also, please just leave the database if you don’t really need to delete them.

    I hope this makes sense 🙂

  • thanks a lot James
    I have 197.508 rows with empty meta_value on wp_postmeta table.
    I think it’s a lot of rows but if you think it shouldn’t affect my database performance much I’m thinking in not to delete them.
    Not all are from ACF fields. 47.460 rows are from ACF fields.

    1- do you think I have to delete them?

    2- if i delete them and I go to modify one post can I insert something on the post after I have deleted it or it’s not possible?

    3- On the table I have for example the field “mytext” and I see that on some of them there is also a field like “_mytext”. When I have the two items the item “_mytext” is for example = field_517ea3ab37372 and the item “myfield” is empty. the two items have the same post_id. If I delete the empty “myfield” row could it be a problem?

    To select only the custom fields empty I do
    SELECT * FROM wp_postmeta WHERE wp_postmeta.meta_value = ” AND (wp_postmeta.meta_key =’myfield’ OR wp_postmeta.meta_key =’myfield2′)
    and I get 47.460 rows

    sorry for the questions and thanksa lot.

  • Hi @susa38

    I think you can test it out to see if it will affect your performance or not. You can create a cloning of your site and then delete the empty rows from the cloning site. You can also use a plugin like Query Monitor to check the performance. Please keep in mind that the performance will vary based on a lot of things, so you will need to get a lot of data.

    If you think the performance is much better on the cloning site, then you can delete the empty rows. If not, you can just leave them alone.

    Deleting the empty rows shouldn’t affect your posts. But to make sure, you can try it on the cloning site too.

    I hope this helps 🙂

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.