What is custom post type in Wordpress ?

Generally some people know wordpress as just a blogging application or in other words blogging platform. In few past years wordpress developed as robust and reliable content management web platform. By default wordpress comes with post and pages as main and default post types. Using wordpress you can create as you like custom content type as you want and it’s called Custom Post Types.

Here we will see how we can create custom post type in wordpress. By Default wordpress package have several post types such as.

  • Post
  • Page
  • Attachment
  • Revision
  • Navigation Menu

You can create your own custom post type and define whatever you like.

For example you want to add movie review section to website then your probable use custom post type called movie-reviews. You want to be able to post review w, some art images, the genre, director. A URL for this section look like this : http://www.domain.com/movie-reviews/  where “movie-review” is custom post type.

Let’s see example for create custom post type. You can place following code to separate plugin and activate it or copy to functions.php file which is located under theme.

add_action( 'init', 'pft_custom_type_init' );

function pft_custom_type_init() {
	$labels = array(
		'name'               => __( 'Movies', 'post type general name', 'plugin-textdomain' ),
		'singular_name'      => __( 'Movie', 'post type singular name', 'plugin-textdomain' ),
		'menu_name'          => __( 'Movies', 'admin menu', 'plugin-textdomain' ),
		'name_admin_bar'     => __( 'Movie', 'add new on admin bar', 'plugin-textdomain' ),
		'add_new'            => __( 'Add Movie', 'book', 'plugin-textdomain' ),
		'add_new_item'       => __( 'Add New Movie', 'plugin-textdomain' ),
		'new_item'           => __( 'New Movie', 'plugin-textdomain' ),
		'edit_item'          => __( 'Edit Movie', 'plugin-textdomain' ),
		'view_item'          => __( 'View Movie', 'plugin-textdomain' ),
		'all_items'          => __( 'All Movies', 'plugin-textdomain' ),
		'search_items'       => __( 'Search Movies', 'plugin-textdomain' ),
		'parent_item_colon'  => __( 'Parent Movies:', 'plugin-textdomain' ),
		'not_found'          => __( 'No Movie found.', 'plugin-textdomain' ),
		'not_found_in_trash' => __( 'No Movies found in Trash.', 'plugin-textdomain' )
	);

	$args = array(
		'labels'             => $labels,
        'description'        => __( 'Description.', 'plugin-textdomain' ),
		'public'             => true,
		'publicly_queryable' => true,
		'show_ui'            => true,
		'show_in_menu'       => true,
		'query_var'          => true,
		'rewrite'            => array( 'slug' => 'movie' ),
		'capability_type'    => 'post',
		'has_archive'        => true,
		'hierarchical'       => false,
		'menu_position'      => null,
		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
	);

	register_post_type( 'movie', $args );
}

I hope this post will help you. Kindly comment here for your question and feedback if any

Please follow and like us:

One thought on “What is custom post type in WordPress ?”

Leave a Reply

Your email address will not be published. Required fields are marked *