Custom Post Type is same as WordPress default post having different post type from WordPress. As we know WordPress regular post has post type ‘post’. So, to create our own post type WordPress provide a function named register_post_type(). This function allows us to define new post type by supported features, labels.
Let’s start with example –
<?php function create_custom_post() { $args() = array(); register_post_type( 'type-name', $args ); } add_action( 'init', 'create_custom_post' ); ?>
In above code, type-name in register_post_type() is the name of custom post type. Here any name can be set according to need of post type.
To register post type according to our needs, we will go through some options and add them to $args array. Let’s add some options (labels, features).
<?php function create_custom_post() { $args = array( 'labels' => array( 'name' => __('Name for type in admin menu'), 'singular_name => __('Singular Name'), 'add_new' => __('Add New'), ), 'description' => 'Description about post type', 'public' => true, 'menu_position' => 10, 'supports' => array('title', 'editor', 'thumbnail', excerpt') ); register_post_type( 'type-name' 'create_custom_post' ); } ?>
Labels
This option defines the different labels for custom post type. Foe example we set for name, singular name, add new. There can be more also like edit, view, search, etc.
Description
The description as name suggests contain some explanation about custom post type like what it does.
Menu Position
In this we can define the position of post type in admin menu. The higher we set it , lower the menu will be placed.
Supports
This option defines WordPress default controls as regular post to custom post type. For a full list take a look at the arguments section in the Codex.
Reference https://codex.wordpress.org/Function_Reference/register_post_type.
Support
Still have any issue feel free to add a ticket and let us know your views to make the code better https://webkul.uvdesk.com/en/customer/create-ticket/
Thanks for Your Time! Have a Good Day!
any interesting article like yours. It is pretty worth
enough for me. In my view, if all web owners and bloggers made good content
as you did, the internet will be much more useful than ever before.
There is certainly a lot to know about this issue.
I love all of the points you’ve made. I am sure this post
has touched all the internet viewers, its really really good post on building up new weblog.