Custom Post Type Perspective

2020-07-31

Register Post Type @ WORDPRESS HANDBOOK

<?php
//CPT
function custom_post_type_perspective() {
    $labels = array(
        'name'                => _x( 'Perspective', 'Post Type General Name', 'tolka' ),
        'singular_name'       => _x( 'Perspective', 'Post Type Singular Name', 'tolka' ),
        'menu_name'           => __( 'Perspectives', 'tolka' ),
        'parent_item_colon'   => __( 'Parent Perspective', 'tolka' ),
        'all_items'           => __( 'All Perspectives', 'tolka' ),
        'view_item'           => __( 'View Perspective', 'tolka' ),
        'add_new_item'        => __( 'Add New Perspective', 'tolka' ),
        'add_new'             => __( 'Add New', 'tolka' ),
        'edit_item'           => __( 'Edit Perspective', 'tolka' ),
        'update_item'         => __( 'Update Perspective', 'tolka' ),
        'search_items'        => __( 'Search Perspective', 'tolka' ),
        'not_found'           => __( 'Not Found', 'tolka' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'tolka' ),
    );

$args = array(
	'label'                 => __( 'Perspective', 'tolka' ),
	'menu_icon'           => 'dashicons-art',
	'description'           => __( 'Perspective', 'tolka' ),
	'labels'                => $labels,
	'supports'              => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', 'page-attributes', 'revisions' ,'category'),
	//'taxonomies' 	      => array('post_tag' , 'industry'),
	'hierarchical'          => true,
	'public'                => true,
	'show_ui'               => true,
	'show_in_menu'          => true,
	'menu_position'         => 5,
	'show_in_admin_bar'     => true,
	'show_in_nav_menus'     => true,
	'can_export'            => true,
	'has_archive'           => true,
	'exclude_from_search'   => false,
	'publicly_queryable'    => true,
	'capability_type'       => 'post',
	'rewrite' => array(
		'slug' => 'perspectives'
	)
	 /*// 'rewrite' => array('slug' => '/', 'with_front' => false), IF YOU WANT TO REMOVE THE SLUG FROM THE URL */

);
    register_post_type( 'perspective', $args );
}

add_action( 'init', 'custom_post_type_perspective', 0 );

//Taxonomy
function create_industries_hierarchical_taxonomy() {

	$labels = array(
	  'name' => _x( 'Industries', 'taxonomy general name' ),
	  'singular_name' => _x( 'Industry', 'taxonomy singular name' ),
	  'search_items' =>  __( 'Search industries' ),
	  'all_items' => __( 'All industries' ),
	  'parent_item' => __( 'Parent Industry' ),
	  'parent_item_colon' => __( 'Parent Industry:' ),
	  'edit_item' => __( 'Edit Industry' ),
	  'update_item' => __( 'Update Industry' ),
	  'add_new_item' => __( 'Add New Industry' ),
	  'new_item_name' => __( 'New Industry Name' ),
	  'menu_name' => __( 'Industries' ),
	);

	register_taxonomy('industry', array('perspective'), array(
	  'hierarchical' => true,
	  'labels' => $labels,
	  'show_ui' => true,
	  'show_admin_column' => true,
	  'query_var' => true,
	  'has_archive' => true,
	  'public'       => true,
	  //'rewrite' => array( 'slug' => 'industry' ),
	));
  }

  //add_action( 'init', 'create_industries_hierarchical_taxonomy', 0 );