Support » Themes and Templates » is it possible to add an extra field to a custom post type?

  • I have created a custom post type in my theme’s functions.php file, called videos. When an author adds a video he will need to provide a youtube ID.
    I know this can be done by adding a custom field, but I don’t think that’s user friendly for the author, because he will have to select youtube ID from the dropdown list first.
    So I was wondering if there is a way to actually hard code the youtube ID field so it is directly displayed underneath the comment box whenever you add or edit a video-post? (And if possible even make this field required?)

Viewing 1 replies (of 1 total)
  • Thread Starter pwkip

    (@pwkip)

    Ok, seems I could use this in my functions.php file đŸ™‚

    add_action("admin_init", "admin_init");
        add_action('save_post', 'save_youtube_id');  
    
        function admin_init(){
            add_meta_box("vidInfo-meta", "Video Options", "meta_options", "video", "side", "high");
        }  
    
        function meta_options(){
            global $post;
            $custom = get_post_custom($post->ID);
            $youtube_id = $custom["youtube_id"][0];
    ?>
        <label>YouTube ID:</label><input name="youtube_id" value="<?php echo $youtube_id; ?>" />
    <?php
        }  
    
    	function save_youtube_id(){
    		global $post;
    		update_post_meta($post->ID, "youtube_id", $_POST["youtube_id"]);
    	}

    With thanks to this great tutorial: http://net.tutsplus.com/tutorials/wordpress/rock-solid-wordpress-3-0-themes-using-custom-post-types/comment-page-3/

Viewing 1 replies (of 1 total)
  • The topic ‘is it possible to add an extra field to a custom post type?’ is closed to new replies.