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.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 | 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.