// Register our Team post type
add_action( 'init', 'create_custom_post_type', 0 );
function create_custom_post_type() {
// Set UI labels for custom post type
$labels = array(
'name' => _x( 'CPT', 'Post Type General Name' ),
'singular_name' => _x( 'CPT', 'Post Type Singular Name' ),
'menu_name' => __( 'CPT' ),
'parent_item_colon' => __( 'Parent CPT' ),
'all_items' => __( 'All CPT' ),
'view_item' => __( 'View CPT' ),
'add_new_item' => __( 'Add New CPT Name' ),
'add_new' => __( 'Add New CPT Name' ),
'edit_item' => __( 'Edit CPT Name' ),
'update_item' => __( 'Update CPT Name' ),
'search_items' => __( 'Search CPT Name' ),
'not_found' => __( 'Not Found' ),
'not_found_in_trash' => __( 'Not found in Trash' ),
);
// Set other options for Custom Post Type
$args = array(
'label' => __( 'CPT' ),
'description' => __( 'CPT' ),
'labels' => $labels,
// Features this CPT supports in Post Editor
'supports' => array( 'title', 'revisions', 'thumbnail', 'page-attributes', 'genesis-cpt-archives-settings' ),
// A hierarchical CPT is like Pages and can have Parent and child items. A non-hierarchical CPT is like Posts.
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => true,
'menu_position' => 25, // 21 Should make it under pages
'can_export' => true,
'has_archive' => false, // This should help stop archive / single posts
'menu_icon' => 'dashicons-admin-users',
'exclude_from_search' => true, // This should help stop archive / single posts
'publicly_queryable' => false, // This should help stop archive / single posts
'capability_type' => 'post',
);
// To prevent any error, make sure this post type doesn't exist
if ( post_type_exists( 'CPT' ) ) {
// This should throw a WP Error if Team is already registered, more here: https://codex.wordpress.org/Class_Reference/WP_Error
return new WP_Error( 'Ooops', __( "This post type is already registered", "my_textdomain" ) );
}else{
// If this post type dosn't exist, register the Team post type
register_post_type( 'CPT', $args);
}
}