WordPress.org

Support

Support » Plugins and Hacks » Problem with saving data from meta box

Problem with saving data from meta box

  • Hi there

    I have a text area in a meta box on the edit page screen. It doesn’t work very well 🙂
    First time I save the page, it works perfect. But when I change the text, the changes arent saved. And if I remove the text, the text stays there…

    This is how I handle the saves/updates… Can someone see what Im doing wrong?

    $meta_value1 = get_post_meta( $post_id, 'box_1', true );
    	$new_meta_value1 = stripslashes( $_POST['box-1-content'] );
    	if ( $new_meta_value1 && '' == $meta_value1 )
    		add_post_meta( $post_id, 'box_1', $new_meta_value1, true ) or update_post_meta( $post_id, 'box_1', $new_meta_value1 );
    	elseif ( $new_meta_value1 != $meta_value1 )
    		update_post_meta( $post_id, 'box_1', $new_meta_value1 );
    	elseif ( '' == $new_meta_value1 && $meta_value1 )
    		delete_post_meta( $post_id, 'box_1', $meta_value1 );
  • The topic ‘Problem with saving data from meta box’ is closed to new replies.