How to Create WordPress custom post type #1
Description:
From Few wordpress version, blog’s admin and wp nerd
can create custom post type. With this new function you can turn wordpress in every kind of thing you want.
In this posts serie i will try to explain all new implementation you can add to your blog.
The Code:
Some about Custom Post Type:
Adding New Custom post type into your Wp Dashboard you will create new custom panel such as “Posts” where you can write particular “post”; for example you can create a “Portfolio” Panel where you will publish all of your creation.
You can use both Custom post type and Taxonomy to create a powerfull project (i’ll talk about taxonomy later).
There are few things you need to know about Custom post Type:
- Basically they don’t include Category and Tags
- Custom Post Type will not published into your blog’s standard Category
- Custom Post Type will create new permalink structure respecting the CPT slug
- You need to create Custom post type archive Manually
Ok Pigi, i’m bored, let’s add new Custom Post Type:
Well, to add new Custom Post Type just add the following code into your function.php file:
add_action('init', 'portfolio_post_type');
function portfolio_post_type() {
register_post_type('portfolio', array(
'labels' => array(
'name' => 'Portfolio',
'singular_name' => 'Project',
'add_new' => 'Add Project to my Portfolio',
'edit_item' => 'Edit project',
'new_item' => 'New Project to my Portfolio',
'view_item' => 'View Portfolio',
'search_items' => 'Search in My Portfolio',
'not_found' => 'WTF no projects Found',
'not_found_in_trash' => 'No project found in Portfolio Trash'
),
'public' => true,
'supports' => array(
'title',
'excerpt',
'editor'
),
'taxonomies' => array('category', 'post_tag')
));
}
Code Explanation:
register_post_type('portfolio', array(
This function tell to wordpress to register new custom post type. “portfolio” will be:
- The name of your Custom post type
- The slug of your post published in this type
'name' => 'Portfolio',
'singular_name' => 'Project',
'add_new' => 'Add Project to my Portfolio',
'edit_item' => 'Edit project',
'new_item' => 'New Project to my Portfolio',
'view_item' => 'View Portfolio',
'search_items' => 'Search in My Portfolio',
'not_found' => 'WTF no projects Found',
'not_found_in_trash' => 'No project found in Portfolio Trash'
With these lines you will define:
- The Label of your Custom Post Type
- The label of the single post creator link
- Other Stuff you can see in the screenshot below
Now Pay Attention please… The following lines will tell to wordpress what you want into your new custom post type writing panel.
'supports' => array(
'title', //post title
'excerpt', //post Excerpt
'editor' // The_content
),
There are a lot of other stuff to include; for example:
- ‘custom-fields’ To include Custom Fields
- ‘author’
- ‘thumbnail’
Check out Wp Function Reference for more details.
'taxonomies' => array('category', 'post_tag')
This line will include in your custom Write Panel Category and Tag Metaboxes, but remember Custom Post will not included into category archive.


