KLoning Spoon

Off course we all known that there’s lot tutorial and discussion about taxonomies and meta box, and from that i learned. And now i’m trying to create an album video of youtube for my client. Thats why i use taxonomies for author and album then meta box for Youtube ID. And this code is just for reminder of me because i have kind of sortem memory loss, hehe.

add_action('init', 'Narasumber');
function Narasumber() {
	register_taxonomy(
		'Narasumber',
		'post',
		array(
			'hierarchical' => false,
			'labels' => array(
			            'name' => __( 'Narasumber' ),
			            'singular_name' => __( 'Narasumber' ),
			            'search_items' => __( 'Search Narasumber' ),
			            'popular_items' => __( 'Popular Narasumber' ),
			            'all_items' => __( 'All Narasumber' ),
			            'edit_item' => __( 'Edit Narasumber' ),
			            'update_item' => __( 'Update Narasumber' ),
			            'add_new_item' => __( 'Add Narasumber' ),
			            'new_item_name' => __( 'New Narasumber' ),
			            'menu_name' => __( 'Narasumber' ),
						'parent_item' => __('Parent Narasumber'),
						'parent_item_colon' => __('Parent Narasumber:')
			),
			'query_var' => true,
			'rewrite' => array('slug' => 'narasumber')
		)
	);
}
add_action('init', 'Album');
function Album() {
	register_taxonomy(
		'Album',
		'post',
		array(
			'hierarchical' => false,
			'labels' => array(
			            'name' => __( 'Album' ),
			            'singular_name' => __( 'Album' ),
			            'search_items' => __( 'Search Album' ),
			            'popular_items' => __( 'Popular Album' ),
			            'all_items' => __( 'All Album' ),
			            'edit_item' => __( 'Edit Album' ),
			            'update_item' => __( 'Update Album' ),
			            'add_new_item' => __( 'Add Album' ),
			            'new_item_name' => __( 'New Album' ),
			            'menu_name' => __( 'Album' ),
						'parent_item' => __('Parent Album'),
						'parent_item_colon' => __('Parent Album:')
			),
			'query_var' => true,
			'rewrite' => array('slug' => 'album')
		)
	);
}
add_action("admin_init", "YoutubeID_init");
add_action('save_post', 'save_YoutubeID_info');
 
    function YoutubeID_init(){
        add_meta_box("YoutubeID-meta", "Youtube ID", "YoutubeID_meta_options", "post", "normal", "high");
    }
    function YoutubeID_meta_options(){
        global $post;
        $meta_info = get_post_custom($post->ID);
        $YoutubeID = $meta_info["YoutubeID"][0];
        echo '

Youtube ID here, example http://www.youtube.com/watch?v=i-MD3beQPwM :

';
    }
 
    function save_YoutubeID_info(){
        global $post;
        update_post_meta($post->ID, "YoutubeID", $_POST["YoutubeID"]);
    }

And this is the preview.

Taxonomies and Meta Box

Now let’s throw in a bit of JavaScript for some fancy, but highly useful fields to your meta box

leverage the WordPress API to define our own custom meta boxes for attaching a document (such as a PDF) to our WordPress pages.

It’s better when developers create a meta box that can show which information is needed and give some explanations to users. In this tutorial, we’ll see how to creating a better meta box in WordPress post editing page.

Creating meta boxes is a crucial part of WordPress theme/plugin development. It’s a way to add an appealing editor to the post screen and avoids forcing users to rely on custom fields. If you’ve ever created a custom post type in WordPress, you’ve probably wanted to add some sort of additional data to it. Sure, you could use custom fields, but that’s ugly. Getting started with custom meta boxes is easy, so let’s dive in!