Support » Plugins » Hacks » Custom MetaBox Data Not Being Added

  • Resolved Howdy_McGee


    I can’t figure it out – it won’t add anythign to the database even though there is 100% a value being passed into $_POST['_desc'] what am I doing wrong?

    /** Add the Meta Box **/
    function add_custom_meta_box() {
    	global $meta_box;
    		'short-desc', // $id
    		'Short Description', // $title
    		'show_custom_meta_box', // $callback
    		'post', // $page
    		'side', // $context
    		'high'); // $priority
    add_action('add_meta_boxes', 'add_custom_meta_box');
    /** The Callback **/
    function show_custom_meta_box() {
    	global $post;
    	// Use nonce for verification
    	echo '<input type="hidden" name="shortdesc_meta_box_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />';
    	// get value of this field if it exists for this post
    	$meta = get_post_custom($post->ID);
    	echo var_dump($meta);
    	// Begin the field table and loop
    	echo '<table class="form-table"><tr><td>';
    		echo '<strong>Enter A Short Description:</strong>
    			<input type="text" name="_desc" id="short-desc" value="'.$meta['_desc'].'" size="30" />';
    	echo '</td></tr></table>'; // end table
    /** Save the Data **/
    function save_custom_meta($post) {
    	// verify nonce
    	if (!wp_verify_nonce($_POST['shortdesc_meta_box_nonce'], basename(__FILE__)))
    		return $post->ID;
    	// check autosave
    	if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
    		return $post->ID;
    	// check permissions
    	if (!current_user_can('edit_post', $post->ID))
    		return $post->ID;
    	echo $_POST['_desc'];
    //	die();
    		update_post_meta($post->ID, '_desc', strip_tags($_POST['_desc']));
    add_action('save_post', 'save_custom_meta', 1, 2);
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz


    You are not collecting the passed ‘save_post’ parameters correctly. Use this:
    function save_custom_meta($id, $post) {

    Then you can use either $id or $post->ID for the post ID.

    I ended up passing it as function save_custom_meta($post_id){} and it worked great. Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom MetaBox Data Not Being Added’ is closed to new replies.