Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

Howdy_McGee on "Custom MetaBox Data Not Being Added"

$
0
0

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;
    add_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();

	if(isset($_POST['_desc']))
		update_post_meta($post->ID, '_desc', strip_tags($_POST['_desc']));
}
add_action('save_post', 'save_custom_meta', 1, 2);

Viewing all articles
Browse latest Browse all 8245

Trending Articles