This is the standard code to register (create) a custom post type. For more detailed information on these and other options check out the WordPress Codex page.
function register_post_types() {
$labels = array(
'name' => _x( 'Practitioners', 'themeblvd' ),
'singular_name' => _x( 'Practitioner', 'themeblvd' ),
'add_new' => _x( 'Add New', 'themeblvd' ),
'add_new_item' => _x( 'Add New Practitioner', 'themeblvd' ),
'edit_item' => _x( 'Edit Practitioner', 'themeblvd' ),
'new_item' => _x( 'New Practitioner', 'themeblvd' ),
'view_item' => _x( 'View Practitioner', 'themeblvd' ),
'search_items' => _x( 'Search Practitioners', 'themeblvd' ),
'not_found' => _x( 'No practitioners found', 'themeblvd' ),
'not_found_in_trash' => _x( 'No practitioners found in Trash', 'themeblvd' ),
'parent_item_colon' => _x( 'Parent Practitioner:', 'themeblvd' ),
'menu_name' => _x( 'Practitioners', 'themeblvd' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => false,
'supports' => array( 'title', 'editor', 'custom-fields', 'thumbnail' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => array( 'slug' => 'practitioners'),
'capability_type' => 'post'
);
register_post_type( 'practitioner', $args );
}
function register_custom_taxonomies() {
$labels = array(
'name' => _x( 'State Name', 'themeblvd' ),
'singular_name' => _x( 'State', 'themeblvd' ),
'search_items' => _x( 'Search States', 'themeblvd' ),
'popular_items' => _x( 'Popular States', 'themeblvd' ),
'all_items' => _x( 'All States', 'themeblvd' ),
'parent_item' => _x( 'Parent State', 'themeblvd' ),
'parent_item_colon' => _x( 'Parent State:', 'themeblvd' ),
'edit_item' => _x( 'Edit State', 'themeblvd' ),
'update_item' => _x( 'Update State', 'themeblvd' ),
'add_new_item' => _x( 'Add New State', 'themeblvd' ),
'new_item_name' => _x( 'New State', 'themeblvd' ),
'add_or_remove_items' => _x( 'Add or remove States', 'themeblvd' ),
'choose_from_most_used' => _x( 'Choose from most used States', 'themeblvd' ),
'menu_name' => _x( 'States', 'themeblvd' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'states'),
'query_var' => 'state'
);
register_taxonomy( 'state', array('practitioner'), $args );
$labels = array(
'name' => _x( 'Certification Name', 'themeblvd' ),
'singular_name' => _x( 'Certification', 'themeblvd' ),
'search_items' => _x( 'Search Certifications', 'themeblvd' ),
'popular_items' => _x( 'Popular Certifications', 'themeblvd' ),
'all_items' => _x( 'All Certifications', 'themeblvd' ),
'parent_item' => _x( 'Parent Certification', 'themeblvd' ),
'parent_item_colon' => _x( 'Parent Certification:', 'themeblvd' ),
'edit_item' => _x( 'Edit Certification', 'themeblvd' ),
'update_item' => _x( 'Update Certification', 'themeblvd' ),
'add_new_item' => _x( 'Add New Certification', 'themeblvd' ),
'new_item_name' => _x( 'New Certification', 'themeblvd' ),
'add_or_remove_items' => _x( 'Add or remove Certifications', 'themeblvd' ),
'choose_from_most_used' => _x( 'Choose from most used Certifications', 'themeblvd' ),
'menu_name' => _x( 'Certifications', 'themeblvd' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_in_nav_menus' => true,
'show_ui' => true,
'show_tagcloud' => true,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'certifications'),
'query_var' => 'certification'
);
register_taxonomy( 'certification', array('practitioner'), $args );
}
function my_cpt_init() {
register_post_types();
register_custom_taxonomies();
}
add_action( 'init', 'my_cpt_init' );
function my_rewrite_flush() {
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'my_rewrite_flush' );Notice “hierarchical” is set to true. This will cause the taxonomy to behave like a category. False or omitted causes the taxonomy to behave like a tag.