Check is custom post type - wordpress

I have a custom post type :
// Custom posttype Events
$labels = array(
'name' => _x('Events', 'Post Type General Name'),
'singular_name' => _x('Events', 'Post Type Singular Name'),
'menu_name' => __('Events'),
'parent_item_colon' => __('Events:'),
'all_items' => __('All Items'),
'view_item' => __('View Item'),
'add_new_item' => __('Add New Event'),
'add_new' => __('Add New'),
'edit_item' => __('Edit Item'),
'update_item' => __('Update Item'),
'search_items' => __('Search Item'),
'not_found' => __('Not found'),
'not_found_in_trash' => __('Not found in Trash'),
);
$args = array(
'labels' => $labels,
'supports' => array('title', 'editor', 'excerpt', 'thumbnail', 'comments', 'trackbacks', 'custom-fields',),
'taxonomies' => array('post_tag'),
'hierarchical' => false,
'rewrite' => array('slug' => __('events')),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 10,
'menu_icon' => 'dashicons-images-alt2',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
);
register_post_type('events', $args);
And a taxonomy for custom post type Events:
// Add new "Type" taxonomy to Events
register_taxonomy('type-events', 'event', array(
'hierarchical' => true,
'labels' => array(
'name' => _x( 'Types', 'taxonomy general name', 'my_theme' ),
'singular_name' => _x( 'Types', 'taxonomy singular name', 'my_theme' ),
'search_items' => __( 'Search Type', 'my_theme' ),
'all_items' => __( 'All Types', 'my_theme' ),
'parent_item' => __( 'Parent Type', 'my_theme' ),
'parent_item_colon' => __( 'Parent Type:', 'my_theme' ),
'edit_item' => __( 'Edit Type', 'my_theme' ),
'update_item' => __( 'Update Type', 'my_theme' ),
'add_new_item' => __( 'Add New Type', 'my_theme' ),
'new_item_name' => __( 'New Type', 'my_theme' ),
'menu_name' => __( 'Types', 'my_theme' ),
),
// Control the slugs used for this taxonomy
'rewrite' => array(
'slug' => 'type-events',
'with_front' => false,
'hierarchical' => true
),
));
In Dashboard Admin, i create two taxonomy type event :
Taxonomies
Custom post type and taxonomy use the same template.
In file template, I want check if it is post type or taxonomy.
Currently, I use is_post_type_archive() to check, but the both return true. That is not what I need.
How to check if this is custom post type or taxonomy?

If you want to check if a post is the custom post type events within the loop you can use this:
<?php if ( get_post_type() === 'events' ) {
/* Do Stuff */
} ?>
If this is outside of the loop, you need to pass the post id into get_post_type():
<?php if ( get_post_type( $post_id ) === 'events' ) {
/* Do Stuff */
} ?>
Edit
You can test for multiple custom post types this way:
<?php if ( get_post_type() === 'events' || get_post_type() === 'promos' || get_post_type() === 'courses' ) {
/* Do Stuff */
} ?>

This is little complicated, maybe the best way is to check with is_post_type_archive() and is_tax(), before you load the themplate, but in your case you may try with get_queried_object().
Codex - get_queried_object
The returned object will have properties taxonomy, term_id, and term_taxonomy_id if this is taxonomy.
So maybe you can use something like get_queried_object()->taxonomy to determine if this is taxonomy and get its name and get_queried_object()->query_var for custom_post_type.
if ( isset( get_queried_object()->taxonomy ) {
//do taxonomy work ...
}
if ( property_exists( get_queried_object()->query_var ) {
//post things
}

function custom_post_type() {
$singular="Car";
$plural="cars";
$labels = array(
'name' => _x( $plural, 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( $singular, 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( $plural, 'text_domain' ),
'name_admin_bar' => __( $singular, 'text_domain' ),
'archives' => __( '$singular Archives', 'text_domain' ),
'attributes' => __( $singular.' Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent '.$singular.':', 'text_domain' ),
'all_items' => __( 'All '.$plural, 'text_domain' ),
'add_new_item' => __( 'Add New '.$singular, 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New '.$singular, 'text_domain' ),
'edit_item' => __( 'Edit '.$singular, 'text_domain' ),
'update_item' => __( 'Update '.$singular, 'text_domain' ),
'view_item' => __( 'View '.$singular, 'text_domain' ),
'view_items' => __( 'View '.$singular, 'text_domain' ),
'search_items' => __( 'Search '.$singular, 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into '.$singular, 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this '.$singular, 'text_domain' ),
'items_list' => __( $singular.' list', 'text_domain' ),
'items_list_navigation' => __( $singular.' list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter '.$singular.' list', 'text_domain' ),
);
$supports =array('title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats');
$texonomies =array('category', 'post_tag');
$args = array(
'label' => __( $singular, 'text_domain' ),
'description' => __( $singular.' Description', 'text_domain' ),
'labels' => $labels,
'supports' => $supports,
'taxonomies' => $texonomies,
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 8,
'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' => 'page',
'menu_icon' => 'dashicons-video-alt'`enter code here`
);
register_post_type( 'post_type', $args );
}
add_action( 'init', 'custom_post_type');

Related

WordPress Query Loop Block not showing Custom Post Types

I have registered a new custom post type by hard coding it into my theme (yes, I could/should move this to a plugin I know!).
But when using the new Query Loop block, the only options under Post Type are 'posts' and 'pages'. Is there something missing from my CPT code causing this issue or could it be something else?
Thanks in advance.
<?php
// Register Custom Post Type
function cpt_listings_function() {
$labels = array(
'name' => _x( 'Listings', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Listing', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Listings', 'text_domain' ),
'name_admin_bar' => __( 'Listings', 'text_domain' ),
'archives' => __( 'Listing Archives', 'text_domain' ),
'attributes' => __( 'Listing Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Listing:', 'text_domain' ),
'all_items' => __( 'All Listings', 'text_domain' ),
'add_new_item' => __( 'Add New Listing', 'text_domain' ),
'add_new' => __( 'Add New Listing', 'text_domain' ),
'new_item' => __( 'New Listing', 'text_domain' ),
'edit_item' => __( 'Edit Listing', 'text_domain' ),
'update_item' => __( 'Update Listing', 'text_domain' ),
'view_item' => __( 'View Listing', 'text_domain' ),
'view_items' => __( 'View Listings', 'text_domain' ),
'search_items' => __( 'Search Listing', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into listing', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this Listing', 'text_domain' ),
'items_list' => __( 'Listings list', 'text_domain' ),
'items_list_navigation' => __( 'Listings list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter listings list', 'text_domain' ),
);
$rewrite = array(
'slug' => 'listing',
'with_front' => true,
'hierarchical' => false,
);
$args = array(
'label' => __( 'Listing', 'text_domain' ),
'description' => __( 'Property Listings Custom Post Type', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'revisions', 'custom-fields', 'page-attributes', 'author' ),
'taxonomies' => array(),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 100,
'menu_icon' => 'dashicons-admin-multisite',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => 'listings',
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => $rewrite,
'capability_type' => array( 'listing', 'listings' ),
'map_meta_cap' => true,
);
register_post_type( 'post_type_listings', $args );
}
add_action( 'init', 'cpt_listings_function', 0 );
I resolved this by adding the following code to my custom post type function above:
'show_in_rest' => true,
More info here: https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-rest-api-support-for-custom-content-types/

WordPress Custom Post Type with role and caps

I am developing real estate website using WordPress Custom Post Type, where user can publish, edit, delete their own post only. Here is my code but unable to achieve target...
function property_post_type() {
$labels = array(
'name' => _x( 'Properties', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Property', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Properties', 'text_domain' ),
'name_admin_bar' => __( 'Property', 'text_domain' ),
'archives' => __( 'Item Archives', 'text_domain' ),
'attributes' => __( 'Item Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All Property', 'text_domain' ),
'add_new_item' => __( 'Add New Property', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Item', 'text_domain' ),
'edit_item' => __( 'Edit Property', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'view_items' => __( 'View Items', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
'items_list' => __( 'Items list', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$args = array(
'label' => __( 'Property', 'text_domain' ),
'description' => __( 'Properties information page.', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'thumbnail', 'revisions'),
'taxonomies' => array( 'region', 'city' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-admin-home',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => array("property", "properties"),
'map_meta_cap' => true,
);
register_post_type( 'property', $args );
}
add_action( 'init', 'property_post_type', 0 );
/****************************************
* Add custom taxonomy for Property *
****************************************/
add_action('init', 'property_categories_register');
function property_categories_register() {
$labels = array(
'name' => 'Category',
'singular_name' => 'Property Category',
'search_items' => 'Search Property Categories',
'popular_items' => 'Popular Property Categories',
'all_items' => 'All Properties Categories',
'parent_item' => 'Parent Property Category',
'edit_item' => 'Edit Property Category',
'update_item' => 'Update Property Category',
'add_new_item' => 'Add New Property Category',
'new_item_name' => 'New Property Category',
'separate_items_with_commas' => 'Separate properties categories with commas',
'add_or_remove_items' => 'Add or remove properties categories',
'choose_from_most_used' => 'Choose from most used properties categories'
);
$args = array(
'label' => 'Property Categories',
'labels' => $labels,
'public' => false,
'hierarchical' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'args' => array( 'orderby' => 'term_order' ),
'rewrite' => array( 'slug' => 'property', 'with_front' => true, 'hierarchical' => true ),
'query_var' => true
);
register_taxonomy( 'property_categories', 'property', $args );
}
add_action( 'init', 'property_post_type', 0 );
add_role('seller', 'Seller', array(
'publish_propety' => true,
'edit_property' => true,
'edit_others_property' => false,
'delete_property' => true,
'delete_others_property' => false,
'read_private_property' => true,
'edit_property' => true,
'delete_property' => true,
'read_property' => true,
// more standard capabilities here
'read' => true,
));
if ( current_user_can('seller') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_seller_uploads');
In users admin panel displaying all post...I want to user can publish, delete, edit only their own post only.
Attaching screenshot users admin panel dashboard..
Screen shot of users admin dashboard

WordPress Custom Post Type and Taxonomy URLs

I made a custom post type and taxonomy so that I could have a structure of /episodes for an archive page that would show all children "terms", /episodes/custom-term to show an archive of a specific term, and /episodes/custom-term/post-title to show single posts.
I was able to get /episodes/custom-term working for any custom term I create. However, I am receiving 404 for /episodes as well as 404 for /episodes/custom-term/post-title.
In the CMS, when I make a post, assuming my custom term is Season One and the post title is Sample Episode. You can go to /episodes/season-one and it will use the "taxonomy-episode_category.php" template to output all posts within Season One. It also knows when creating the post that the permalink is /episodes/season-one/sample-episode however it reaches a 404 page.
I am not sure where to go from here or if I am doing this wrong.
function episodes() {
$labels = array(
'name' => _x( 'Episodes', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Episodes', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Episodes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All Episodes', 'text_domain' ),
'view_item' => __( 'View Item', 'text_domain' ),
'add_new_item' => __( 'Add New Item', 'text_domain' ),
'add_new' => __( 'Add new episode', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' )
);
$rewrite = array(
'slug' => 'episodes/%episode_cat%',
'with_front' => false,
'pages' => true,
'feeds' => true
);
$args = array(
'label' => __( 'episodes', 'text_domain' ),
'description' => __( 'All episodes', 'text_domain' ),
'labels' => $labels,
'supports' => array('title' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
'query_var' => true,
'_builtin' => false
);
register_post_type( 'episodes_listing', $args );
}
add_action( 'init', 'episodes', 0 );
function episodes_taxomony() {
$labels = array(
'name' => _x( 'Episodes Categories', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Episodes', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Episode Categories', 'text_domain' ),
'all_items' => __( 'All Items', 'text_domain' ),
'parent_item' => __( 'Parent Item', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'new_item_name' => __( 'New Item Name', 'text_domain' ),
'add_new_item' => __( 'Add new episode', 'text_domain' ),
'edit_item' => __( 'Edit Item', 'text_domain' ),
'update_item' => __( 'Update Item', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
'search_items' => __( 'Search Items', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove items', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used items', 'text_domain' ),
'not_found' => __( 'Not Found', 'text_domain' )
);
$rewrite = array(
'slug' => 'episodes',
'with_front' => false,
'hierarchical' => true
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
'query_var' => true,
'rewrite' => $rewrite
);
register_taxonomy( 'episodes_category', array('episodes_listing'), $args );
}
add_action( 'init', 'episodes_taxomony', 0 );
function filter_post_type_link($link, $post)
{
if ($post->post_type != 'episodes_listing')
return $link;
if ($cats = get_the_terms($post->ID, 'episodes_category')) {
$link = str_replace('%episode_cat%', array_pop($cats)->slug, $link);
return $link;
}
}
add_filter('post_type_link', 'filter_post_type_link', 10, 2);
Turns out pagination was working correctly when I set permalink structure to default instead of Post name. To use post name I was able to use the exact code along with a new function:
function add_rewrite_rules() {
add_rewrite_rule('episodes/(.+?)/page/?([0-9]{1,})/?$', 'index.php', 'top');
}
add_filter('init', 'add_rewrite_rules')

show white screen for single-type.php and archive-type.php file in wordpress

i have created custom post type 'gallery' to display in single page named single-gallery.php and archive-gallery.php file but it provides me white screen
Please help me to solve my problem... here is my code..
// Register Custom Post Type
function gallery() {
$labels = array(
'name' => _x( 'gallery', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'gallery', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'gallery', 'text_domain' ),
'parent_item_colon' => __( 'Parent gallery', 'text_domain' ),
'all_items' => __( 'All gallery', 'text_domain' ),
'view_item' => __( 'View gallery', 'text_domain' ),
'add_new_item' => __( 'Add New gallery', 'text_domain' ),
'add_new' => __( 'New gallery', 'text_domain' ),
'edit_item' => __( 'Edit gallery', 'text_domain' ),
'update_item' => __( 'Update gallery', 'text_domain' ),
'search_items' => __( 'Search gallerys', 'text_domain' ),
'not_found' => __( 'No gallerys found', 'text_domain' ),
'not_found_in_trash' => __( 'No gallerys found in Trash', 'text_domain' ),
);
$args = array(
'label' => __( 'gallery', 'text_domain' ),
'description' => __( 'gallery information pages', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'custom-fields', ),
'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'gallery', $args );
}
// Hook into the 'init' action
add_action( 'init', 'gallery', 0 );
Sometimes just visiting the Permalink settings in wordpress admin fixes such issues. Have you tried that?

wordpress custom post type with custom taxonomy

I have added a custom post and a custom taxonomy to my wordpress theme.
problem is , when im trying to add new taxonomy im getting a javascript error:
(the taxonomy is added but screen needs to be refreshed before i can see it)
f.responses[0] is undefined
[Break On This Error]
...or","")}}});f.children().css("backgroundColor","#f33")}return false});a("#submit...
This is my Code for adding the custom post and taxonomy
add_action('init', 'catalog_register');
function catalog_register() {
$labels=...;
$args = array(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => true,
'menu_position' => 101,
'supports' => array('title','editor','thumbnail')
);
register_post_type( 'catalog' , $args );
}
here is my custom taxonomy code:
function create_catalog_taxonomies() {
$labels =array(...);
register_taxonomy("product_category", array("catalog"), array(
"hierarchical" => true,
"labels" => $labels,
'public' => true,
'query_var' => true,
'show_ui' => true,
'rewrite' => true
));
}
add_action( 'init', 'create_catalog_taxonomies', 0 );
what is wrong here ?
You have already registered post type catalog, so just change the taxonomy registration to following syntax:
$args = array(
'hierarchical' => true,
'labels' => $labels,
'public' => true,
'query_var' => true,
'show_ui' => true,
'rewrite' => true
);
register_taxonomy('product_category', 'catalog', $args);
This error also happens when the functions.php file contains a whitespace before the starting
code for custom post type
function my_post_type() {
$labels = array(
'name' => _x( 'Name', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Name', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Names', 'text_domain' ),
'name_admin_bar' => __( 'Names', 'text_domain' ),
'archives' => __( 'Item Names', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All Names', 'text_domain' ),
'add_new_item' => __( 'Add New Names', 'text_domain' ),
'add_new' => __( 'Add New Name', 'text_domain' ),
'new_item' => __( 'New Name', 'text_domain' ),
'edit_item' => __( 'Edit Name', 'text_domain' ),
'update_item' => __( 'Update Name', 'text_domain' ),
'view_item' => __( 'View Name', 'text_domain' ),
'search_items' => __( 'Search Name', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
'items_list' => __( 'Items list', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$args = array(
'label' => __( 'Names', 'text_domain' ),
'description' => __( 'Names Description', 'text_domain' ),
'labels' => $labels,
'supports' => array('title','author','excerpt','editor','thumbnail','revisions' ),
'hierarchical' => false,
'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' => 'page',
);
register_post_type( 'Name', $args );
}
add_action( 'init', 'my_post_type', 0 );
Custom Taxonomy
add_action( 'init', 'add_my_taxonomies', 0 );
function add_years_taxonomies() {
register_taxonomy('years', 'repository', array(
'hierarchical' => true,'labels' => array('labels' => array(
'name' => _x( 'Years', 'taxonomy general name' ),
'singular_name' => _x( 'Year', 'taxonomy singular name' ),
'search_items' => __( 'Search Years' ),
'all_items' => __( 'All Years' ),
'parent_item' => __( 'Parent ' ),
'parent_item_colon' => __( 'Parent Year:' ),
'edit_item' => __( 'Edit Year' ),
'update_item' => __( 'Update Year' ),
'add_new_item' => __( 'Add New Year' ),
'new_item_name' => __( 'New Year Name' ),
'menu_name' => __( 'Years' ),
),
'rewrite' => array(
'slug' => 'years',
'with_front' => false,
'hierarchical' => true
),
));
}

Resources