Create Custom Post Type with category

A custom post type can be added to WordPress via the register_post_type() function. This function allows you to define a new post type by its labels, supported features, availability and other specifics.

add_action('init','postype');
function postype() {
$labels = array(
'name' => _x('Postype', 'post type general name'),
'singular_name' => _x('Postype', 'post type singular name'),
'add_new' => _x('Add New Postype', 'New Postype'),
'add_new_item' => __('Add New Postype'),
'edit_item' => __('Edit Postype'),
'new_item' => __('New Postype'),
'view_item' => __('View Postype'),
'search_items' => __('Search Postype'),
'not_found' =>  __('Nothing found'),
'not_found_in_trash' => __('Nothing found in Trash'),
'parent_item_colon' => ''
);

$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'menu_icon' => get_stylesheet_directory_uri() . '/article16.png',
'rewrite' => array('slug' => 'postype'),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title','editor','page-attributes','thumbnail','custom-fields','excerpt','comments'),
'taxonomies' => array('post_tag'),
'has_archive' => true
);
register_post_type( 'postype' , $args );
}

// Creating custom Taxanomy
add_action( 'init', 'create_postype_category' );

function create_postype_category() {
$labels = array(
'name' => _x( 'Location', 'taxonomy general name' ),
'singular_name' => _x( 'Location', 'taxonomy singular name' ),
'search_items' =>  __( 'Search Location' ),
'all_items' => __( 'All Location' ),
'parent_item' => __( 'Parent Location' ),
'parent_item_colon' => __( 'Parent Location:' ),
'edit_item' => __( 'Edit Location' ),
'update_item' => __( 'Update Location' ),
'add_new_item' => __( 'Add New Location' ),
'new_item_name' => __( 'New Location' ),
);

register_taxonomy('postype-category','postype',array(
'hierarchical'  => true,
'show_ui'         => true,
'labels'         => $labels
));
}