Advertisement
Guest User

CPT and taxonomy

a guest
Mar 27th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.19 KB | None | 0 0
  1. $labels = array(
  2.   'name' => 'Colors',
  3.   'singular_name' => 'Color',
  4.   'search_items' =>  'Search Color',
  5.   'all_items' => 'All Colors',
  6.   'parent_item' => 'Parent Color',
  7.   'parent_item_colon' => 'Parent Color',
  8.   'edit_item' => 'Modify Color',
  9.   'update_item' => 'Update Color',
  10.   'add_new_item' => 'Add new Color',
  11.   'new_item_name' => 'New Color',
  12.   'menu_name' => 'Colors',
  13. );
  14. register_taxonomy(
  15.   'color',
  16.   null, //tried array('post', 'myposttype') too, permalinks flushed
  17.   array(
  18.   'hierarchical' => true,
  19.   'label' => 'Colors',
  20.   'labels' => $labels,
  21.   'show_ui' => true,
  22.   'query_var' => 'color',
  23.   'rewrite' => array( 'slug' => 'myposttype/color', 'with_front' => false ),
  24.   'singular_label' => 'Color'
  25. ));
  26.  
  27.  
  28.  
  29. function register_cpt_myposttype() {
  30.   $labels = array(
  31.   'name' => 'MyPostTypes',
  32.   'singular_name' => 'MyPostType',
  33.   'add_new' => 'Add MyPostType',
  34.   'add_new_item' => 'New MyPostType',
  35.   'edit_item' => 'Edit MyPostType',
  36.   'new_item' => 'New MyPostType',
  37.   'view_item' => 'View MyPostType',
  38.   'search_items' => 'Search MyPostType',
  39.   'not_found' => 'Not Found MyPostType',
  40.   'not_found_in_trash' => 'Not Found in trash MyPostType',
  41.   'parent_item_colon' => 'Parent MyPostType',
  42.   'menu_name' => 'MyPostTypes',
  43.   );
  44.   $args = array(
  45.   'labels' => $labels,
  46.   'hierarchical' => false,
  47.   'description' => 'My Custom Post Type',
  48.   'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'post-formats' ),
  49.   'taxonomies' => array( 'color' ),
  50.   'public' => true,
  51.   'show_ui' => true,
  52.   'show_in_menu' => true,
  53.   'show_in_nav_menus' => true,
  54.   'publicly_queryable' => true,
  55.   'exclude_from_search' => false,
  56.   'has_archive' => 'myposttype',
  57.   'query_var' => true,
  58.   'can_export' => true,
  59.   'rewrite' => array( 'slug'=>'myposttype', 'with_front'=> false ),
  60.   'capability_type' => 'post'
  61.   );
  62.   register_post_type( 'myposttype', $args );
  63. }
  64. add_action( 'init', 'register_cpt_myposttype' );
  65.  
  66.  
  67. function associate_taxonomies() {
  68.   register_taxonomy_for_object_type('color', 'post');
  69.   register_taxonomy_for_object_type('color', 'myposttype');
  70. }
  71. add_action('init', 'associate_taxonomies');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement