0

add_action('init', function() {
 register_post_type('portfolio', [
  'label' => __('Portfolio', 'txtdomain'),
  'public' => true,
  'menu_position' => 5,
  'menu_icon' => 'dashicons-book',
  'supports' => ['title', 'editor', 'thumbnail', 'author', 'revisions', 'comments'],
  'show_in_rest' => true,
  'rewrite' => ['slug' => 'portfolio'],
  'taxonomies' => ['portfolio_categories'],
  'labels' => [
   'singular_name' => __('Portfolio', 'txtdomain'),
   'add_new_item' => __('Add new Portfolio', 'txtdomain'),
   'new_item' => __('New Portfolio', 'txtdomain'),
   'view_item' => __('View Portfolio', 'txtdomain'),
   'not_found' => __('No Portfolio found', 'txtdomain'),
   'not_found_in_trash' => __('No Portfolio found in trash', 'txtdomain'),
   'all_items' => __('All Portfolio', 'txtdomain'),
   'insert_into_item' => __('Insert into Portfolio', 'txtdomain')
  ],		
 ]);
   register_taxonomy('portfolio_categories', ['portfolio'], [
  'label' => __('Portfolio Categories', 'txtdomain'),
  'hierarchical' => true,
  'rewrite' => ['slug' => 'portfolio_categories'],
  'show_admin_column' => true,
  'show_in_rest' => true,
  'labels' => [
   'singular_name' => __('Portfolio Categories', 'txtdomain'),
   'all_items' => __('All Portfolio Categories', 'txtdomain'),
   'edit_item' => __('Edit Portfolio Categorie', 'txtdomain'),
   'view_item' => __('View Portfolio Categorie', 'txtdomain'),
   'update_item' => __('Update Portfolio Categorie', 'txtdomain'),
   'add_new_item' => __('Add New Portfolio Categorie', 'txtdomain'),
   'new_item_name' => __('New Portfolio Categorie', 'txtdomain'),
   'search_items' => __('Search Portfolio Categorie', 'txtdomain'),
   'parent_item' => __('Parent Portfolio Categorie', 'txtdomain'),
   'parent_item_colon' => __('Parent Portfolio Categorie:', 'txtdomain'),
   'not_found' => __('No Portfolio Categorie found', 'txtdomain'),
  ]
 ]);
 register_taxonomy_for_object_type('portfolio_categories', 'portfolio');
});

Jagdish Sarma Asked question October 15, 2021
Add a Comment