Forums

Front-end Editor
[resolved] Suggestion: Test for 0 on Meta Value Save (2 posts)

  1. C. Spencer Beggs
    Member
    Posted 1 year ago #

    Hi, scribu,

    I ran across another zero-as-a-value related bug. When I input a value of zero for a custom post meta field, the plugin was deleting the old value because the string '0' is treated as empty in PHP, though one would want to retain the ability to have the meta value be deleted if it is truly empty. I hacked the save function in my post.php file like so to get round this:

    if ($new_value === '0')
    			update_post_meta( $post_id, $key, $new_value, $old_value );
    		else if (!$new_value)
    			delete_post_meta( $post_id, $key, $old_value );
    		else
    			update_post_meta( $post_id, $key, $new_value, $old_value );

    Thanks again for this wonderful plugin.

  2. scribu
    Member
    Posted 1 year ago #

    Fixed in the development version (2.0.2-alpha).

    Thanks for reporting.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic