barn2plugins / easy-post-types-fields

Easy Post Types and Fields plugin for WordPress.
https://wordpress.org/plugins/easy-post-types-fields/
Other
1 stars 0 forks source link

Can't delete custom field value #8

Closed FaycalBoutam closed 1 year ago

FaycalBoutam commented 1 year ago

Summary Easy Post Types and Fields > Custom Field value cannot be deleted

Steps to replicate I have a custom post type called Articles. Visit this link to edit the custom post: https://adrian.wppluginsupport.net/wp-admin/post.php?post=1004&action=edit Try removing the value of the "My Custom Field" field, save, refresh the page, and you'll see that the value is not deleted.

Outcome I cannot delete the value of the custom field I created.

Expected Outcome I should be able to delete the value of the custom field I created.

It happens in this line, removing that second check fixes the issue.

Ticket: https://secure.helpscout.net/conversation/2347577064/92004?folderId=7603842

LuigiPulcini commented 1 year ago

Instead of removing the second condition, I would suggest to transform the if clause as follows:

if ( isset( $postdata[ $meta_key ] ) && '' !== $postdata[ $meta_key ] ) {
    update_post_meta( $post_id, $meta_key, $postdata[ $meta_key ] );
} else {
    delete_post_meta( $post_id, $meta_key );
}

This way we don't litter the database with unnecessary metadata.

amirition commented 1 year ago

Thanks @FaycalBoutam and @LuigiPulcini. I have fixed this in the new release of the plugin.