How to Create Custom Post types in Wordpess

How to Create Custom Post types in Wordpess

A website plays an important in any business. If you want to want to enhance your business in the future days, you cannot do it without an online presence. In addition, properly maintained websites can help you to improve your business. WordPress is one of the great platforms for creating your website at reasonable pricing. WordPress can provide you an advanced and quite flexible technology for creating your website. One of the useful features present in WordPress is Custom post types. Let see the needs of creating a custom type in WordPress.

What is Custom post type?
Custom post types also look as if your regular posts, but it has a wide range of post type values. The custom post type can be easily created in WordPress by using a plugin. This type of method is safe and easy, therefore it is highly recommended for the beginners. The full-fledged CMS can be easily created by using the custom post types. Some of the default post types come with WordPress such as page, revision, post, etc. However, the custom type post can create by your own.

WordPress Custom post types:
WordPress custom post types in simple, the posts on the website are sorted beads on their content. The default post types in WordPress such as attachment, page, post, etc. These are all stored in the posts database table. The post types are differentiated by using the column called post_type. If you are using the default post type means, you cannot able to differentiate the content they contain. The posts present in the admin control panel have appeared on the same list.

The need for custom post types:
Sometimes, you need to sort out your content in a structured manner on your site. You may want to explain a wide variety of things within your blog or need to add multiple authors’ definitions and some more. By using the default post type, you cannot do this wide variety of operations. To overcome these impacts, the custom post type is created. It plays a very important role in WordPress.

There are two different ways are available to create the custom post types. There are seen below:

Create the custom post types through plugin:
The plugin is considered as a great way or easiest trick for creating the custom post types. Most of the novices or non-programmers can be easily achieved their goal through this ideal way. If you want to create and manage custom posts type in a WordPress means, you need to choose the Custom Post Type UI. The process can be done with WordPress version 3.5 or more.

Creating custom type manually by adding codes in functions.php file in your theme:
Once the plugin is deactivated, the custom post type will not be visible for you. The stored information in your custom post types still exists, but you cannot able to access it when you want. In that trouble situation, you have to create the custom post type manually. If you want to make them assign a properly, you have to prefer the custom post types. It will help to arrange the posts as if you want.

Find the below code for custom post type to add in functions.php file in your theme with explanation..


  1. // Custom Post type for Holiday
  2. function holiday_custom_post_type() {
  3. $labels = array(
  4. 'name' => __( 'Holidays' ),
  5. 'singular_name' => __( 'Holiday'),
  6. 'menu_name' => __( 'Holiday'),
  7. 'parent_item_colon' => __( 'Parent Holiday'),
  8. 'all_items' => __( 'All Holidays'),
  9. 'view_item' => __( 'View Holiday'),
  10. 'add_new_item' => __( 'Add New Holiday'),
  11. 'add_new' => __( 'Add New'),
  12. 'edit_item' => __( 'Edit Holiday'),
  13. 'update_item' => __( 'Update Holiday'),
  14. 'search_items' => __( 'Search Holiday'),
  15. 'not_found' => __( 'Not Found'),
  16. 'not_found_in_trash' => __( 'Not found in Trash')
  17. );
  18. $args = array(
  19. 'label' => __( 'holiday'),
  20. 'description' => __( 'All Holiday Details'),
  21. 'labels' => $labels,
  22. 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'revisions', 'custom-fields'),
  23. 'public' => true,
  24. 'hierarchical' => false,
  25. 'show_ui' => true,
  26. 'show_in_menu' => true,
  27. 'show_in_nav_menus' => true,
  28. 'show_in_admin_bar' => true,
  29. 'has_archive' => true,
  30. 'can_export' => true,
  31. 'exclude_from_search' => false,
  32. 'yarpp_support' => true,
  33. 'taxonomies' => array('post_tag'),
  34. 'publicly_queryable' => true,
  35. 'capability_type' => 'page'
  36. );
  37. register_post_type( 'holiday', $args );
  38. }
  39. add_action( 'init', 'holiday_custom_post_type', 0 );
  41. //create Taxonomy for post type
  42. add_action( 'init', 'holiday_custom_taxonomy', 0 );
  44. //Added the type of post types
  45. function holiday_custom_taxonomy() {
  47. $labels = array(
  48. 'name' => _x( 'Category', 'taxonomy general name' ),
  49. 'singular_name' => _x( 'Category', 'taxonomy singular name' ),
  50. 'search_items' => __( 'Search Types' ),
  51. 'all_items' => __( 'All Category' ),
  52. 'parent_item' => __( 'Parent Category' ),
  53. 'parent_item_colon' => __( 'Parent Category:' ),
  54. 'edit_item' => __( 'Edit Category' ),
  55. 'update_item' => __( 'Update Category' ),
  56. 'add_new_item' => __( 'Add New Category' ),
  57. 'new_item_name' => __( 'New Category Name' ),
  58. 'menu_name' => __( 'Category' ),
  59. );
  61. register_taxonomy('category',array('holiday'), array(
  62. 'hierarchical' => true,
  63. 'labels' => $labels,
  64. 'show_ui' => true,
  65. 'show_admin_column' => true,
  66. 'query_var' => true,
  67. 'rewrite' => array( 'slug' => 'category' ),
  68. ));
  69. }

Labels: The Labels option should have an array defining the various labels that feature a custom post.

Description: it will help you to give a simple explanation about your custom post type like why you are using it and what it does.
Public: a wide variety of things can be controlled by using the public option. You have to set the default value False if your post is going to visible to the visitors and authors, which means, it will not be displayed in the admin control panel.

Exclude_from_search: If your post is going to be, appear on the normal search results. Therefore, your default value should be opposite to the public’s value.

Publicly_queryable: your default value is similar to the public’s value if the posts are retrieved by using the URL or some other advanced usage.

Show_ui: if the post editor and menu links appear in the admin control panel, the default value should be equal to the public’s value.

Show_in_nav_menus: the default value is similar to the public value if the posts of this type are attached to navigation menus. They are created by using the appearance on the menu screen.

Show_in_menu: the links are hidden by false value. True can add your link as a top-level link. String options can help you to place the sub-link in the existing top-level link.

Hierarchical: if the posts are assigned to a parent post, then the array must contain the feature page attributes.

Taxonomies: the taxonomies are arranged to the posts of this custom type. The taxonomies will not be created; it is only for registration process.

These are all the important benefits and needs available in creating the custom post type in WordPress.

About webfriendy

Sumit Malviya | Web developer and Blogger

View all posts by webfriendy →

Leave a Reply

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