We have a lot of rogue custom fields. I feel that we can clear significant space in the DB if we remove the blank values. If I query my database with the following:
select * from wp_postmeta where meta_value=""
I get 871038 (!)
My question is, is it safe to delete these? Are there any potential issues that could arise from doing this?
You should be fine deleting empty custom fields.
The main reason is, that get_post_meta( $id, 'metakey', true )
returns an empty string if the field is not set, so it is the same as having an empty record set.
get_post_meta( $id, 'metakey', false )
, returns an empty array if no value is set, so you should be fine too.
The only problem you could face is with getting all metadata at once (get_post_meta( $id )
), because in the return to this call the empty values are set, but they are not set, if there is no record in the database. This could cause a few PHP_WARNING
s, but you should be okay.