ocastaneda82
2/20/2017 - 11:44 PM

Crea metabox wordpress 2, imagen uploader

Crea metabox wordpress 2, imagen uploader

/*
 * Add a meta box
 */
add_action( 'admin_menu', 'mini_meta_box_add' );

function mini_meta_box_add() {
	add_meta_box('mishadiv', // meta box ID
		'Miniatura Noticias', // meta box title
		'miniatura_meta_box', // callback function that prints the meta box HTML
		'custom-noticias', // post type where to add it
		'side', // priority
		'low' ); // position
}

/*
 * Meta Box HTML
 */
function miniatura_meta_box( $post ) {
	wp_nonce_field(basename(__FILE__),'meta-box-nonce');
	$meta_key = 'second_featured_img';
	echo misha_image_uploader_field( $meta_key, get_post_meta($post->ID, $meta_key, true) );
}

/*
 * Save Meta Box data
 */
add_action('save_post', 'misha_save');

function misha_save( $post_id ) {
	if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
		return $post_id;

	$meta_key = 'second_featured_img';

	update_post_meta( $post_id, $meta_key, $_POST[$meta_key] );
	return $post_id;
}