Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $labels = array(
- 'name' => 'Colors',
- 'singular_name' => 'Color',
- 'search_items' => 'Search Color',
- 'all_items' => 'All Colors',
- 'parent_item' => 'Parent Color',
- 'parent_item_colon' => 'Parent Color',
- 'edit_item' => 'Modify Color',
- 'update_item' => 'Update Color',
- 'add_new_item' => 'Add new Color',
- 'new_item_name' => 'New Color',
- 'menu_name' => 'Colors',
- );
- register_taxonomy(
- 'color',
- null, //tried array('post', 'myposttype') too, permalinks flushed
- array(
- 'hierarchical' => true,
- 'label' => 'Colors',
- 'labels' => $labels,
- 'show_ui' => true,
- 'query_var' => 'color',
- 'rewrite' => array( 'slug' => 'myposttype/color', 'with_front' => false ),
- 'singular_label' => 'Color'
- ));
- function register_cpt_myposttype() {
- $labels = array(
- 'name' => 'MyPostTypes',
- 'singular_name' => 'MyPostType',
- 'add_new' => 'Add MyPostType',
- 'add_new_item' => 'New MyPostType',
- 'edit_item' => 'Edit MyPostType',
- 'new_item' => 'New MyPostType',
- 'view_item' => 'View MyPostType',
- 'search_items' => 'Search MyPostType',
- 'not_found' => 'Not Found MyPostType',
- 'not_found_in_trash' => 'Not Found in trash MyPostType',
- 'parent_item_colon' => 'Parent MyPostType',
- 'menu_name' => 'MyPostTypes',
- );
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => false,
- 'description' => 'My Custom Post Type',
- 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
- 'taxonomies' => array( 'color' ),
- 'public' => true,
- 'show_ui' => true,
- 'show_in_menu' => true,
- 'show_in_nav_menus' => true,
- 'publicly_queryable' => true,
- 'exclude_from_search' => false,
- 'has_archive' => 'myposttype',
- 'query_var' => true,
- 'can_export' => true,
- 'rewrite' => array( 'slug'=>'myposttype', 'with_front'=> false ),
- 'capability_type' => 'post'
- );
- register_post_type( 'myposttype', $args );
- }
- add_action( 'init', 'register_cpt_myposttype' );
- function associate_taxonomies() {
- register_taxonomy_for_object_type('color', 'post');
- register_taxonomy_for_object_type('color', 'myposttype');
- }
- add_action('init', 'associate_taxonomies');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement