Posted in:

How to Create Custom Post Types on WordPress Sites

Generally, there are five default post types that can be used from the core installation of WordPress, including post, page, attachment, revision, and navigation. Since WordPress version 3.0, however, people are allowed to add their own custom post type freely. The custom post type enables more possibilities for you and makes all web content classified into different structures properly.

what is custom post typeSince WordPress custom post types are in good graces of webmasters, we make this guide to help people create one with ease. We have presented 2 methods that help you do this with ease. First of all, let’s have a quick view on the five default post types. If they really cannot meet your needs, then you can create a new one as you wish.

  • Post – This is a standard type used for blog posts. It is displayed in a reverse sequential order, meaning that the latest updated content will be presented at first.
  • Page – Unlike Post, Page is displayed outside the normal time base, but is organized in a hierarchical structure without the ability of carrying tags and categories.
  • Attachment – This is a special post type that holds information about a WordPress uploaded file like the image file.
  • Revision – This type is used to hold a draft post and the revisions of all the published posts.
  • Navigation Menu – It is used to hold information about a single item in the navigation menu system of WordPress.

Make Full Use of Custom Post Type UI

The Custom Post Type UI is selected in this guide thanks to its flexibility and usability, with which you are able to create custom post types easily without the need of any professional skills. Once after installing WordPress Plugins, you can finish all procedures via an understandable interface. And now, let’s get started to finish the installation via your WordPress Dashboard > Plugins > Add New. And then, the CPT UI is shown in the menu bar.

Move the mouse onto CPT UI and pitch on the second option called Add New. This is where to create a new post type according to your needs. Fill out the post type name, label, singular label and description as required and then click “Create Custom Post Type” button to confirm all information.

create custom post type

What’s more, CPT UI enables some advanced options for label customization, including Menu Name, Add New, And New Item, and so on. Note that, if you have no idea about how to customize the given options, you can leave them blank and this plugin will generate labels automatically.

In addition to custom post type, you are also allowed to create custom taxonomy, which helps you further classify the content included in a post type. Create a custom taxonomy if needed and determine which post type(s) should be attached to this newly created taxonomy. Finally, click “Create Custom Taxonomy” button.

create custom taxonomy

If there is a need to modify the custom post types or taxonomies, you can go to CPT UI > Manage Post Types/Manage Taxonomies. This is where to delete or edit the existing custom post types or taxonomies. And also, you can get code of certain post types.

manage post types

Besides, if there are any questions to Custom Type UI, you can go to Dashboard > CPT UI which shows you some FAQs and the links to useful tutorials. To be honest, the use of CPT UI plugin helps you save a lot of trouble because you just need to make full use of it as required after installing this plugin. In fact, there are some other options available for you, such as Types, WCK, Custom Post Type Maker, and so on.

  • Types – This plugin leaves enough room for WordPress customization, with which you are able to add custom post types, taxonomy and custom fields as needed. Besides, it enables taxonomy to be associated with custom post types and allow you to take full control of all features. (Plugin URL: https://wordpress.org/plugins/types/)
  • WCK – It is a great Custom Post Types creator that helps you create custom post type, custom fields and taxonomies without the need for any programming knowledge. WCK comes with a user-friendly interface. This is where to create and edit custom post types. (Plugin URL: https://wordpress.org/plugins/wck-custom-fields-and-custom-post-types-creator/)
  • Custom Post Type Maker – This plugin enables a simple way to create and manage custom post types. Besides, you are encouraged to contact the support team to get more possibilities. (Plugin URL: https://wordpress.org/plugins/custom-post-type-maker/)

In addition to WordPress plugin, you can also create a custom type manually only if you have had a general understating of coding stuff. If so, the second method can make a big difference for you.

Create Custom Post Type with Coding Stuff

In order to add a custom post type, you can make use of your WordPress theme and theregister_post_type() function. This function is able to help you create and define a new type with different labels, features, and specifics.

The coding stuff required has been already presented in the following. You can go to WordPress Dashboard > Appearance > Editor. After selecting your current theme, you simply need to click functions.php in the list on the right and adding the following lines of code. Here, we name the custom post type as “movie”. You are allowed to replace to any other post types as you want.

add_action( 'init', 'create_post_type' );  function create_post_type() {    register_post_type( 'acme_movie',      array(        'labels' => array(          'name' => __( 'movies' ),          'singular_name' => __( 'movie' )        ),        'public' => true,        'has_archive' => true,      )    );  }  

This is the simplest form that has almost no customization. As the CPT UI plugin gives you advanced options, the following coding stuff is created to add more possibilities to the custom post type. You are required to copy and paste the code to the functions.php file and adjust certain commands if needed.

function create_post_type() {    $labels = array(      'name'               => _x( 'Movies', 'post type general name' ),      'singular_name'      => _x( 'Movie', 'post type singular name' ),      'add_new'            => _x( 'Add New', 'actor' ),      'add_new_item'       => __( 'Add New Movie' ),      'edit_item'          => __( 'Edit Movie' ),      'new_item'           => __( 'New Movie' ),      'all_items'          => __( 'All Moviess' ),      'view_item'          => __( 'View Movie' ),      'search_items'       => __( 'Search Movies' ),      'not_found'          => __( 'No movies found' ),      'not_found_in_trash' => __( 'No movies found in the Trash' ),       'parent_item_colon'  => '',      'menu_name'          => 'Movies'    );    $args = array(      'labels'        => $labels,      'description'   => 'Holds our movies and movie specific data',      'public'        => true,      'menu_position' => 5,      'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),      'has_archive'   => true,    );    register_post_type( 'movie', $args );   }  add_action( 'init', 'create_post_type' );  

You’d better tailor it by making use of some parameters, including labels, public or not, description, supports, capability_type, hierarchical level, query_var, rewrite, author, comment, and many more.

  • Label – This option is an array indicating the different labels of the custom post types. The name will be displayed in the sidebar of the WordPress admin panel.
  • Public or Not – Configuring this option with the True value can make this new post type visible.
  • Description – You can add a short description of this post type with some simple words.
  • menu_position – Determine the position of a custom post type. For example, the number 5 means this custom post type is the fifth one in the post menu.
  • Supports – This allows you to display support for comment, revision, post format and many more, but not only the title and editor that are shown by default.

After finishing these configurations and saving the changes, you can have your new post type established, being able to publish posts and checking the existing articles. To get the utmost out of the above-mentioned code, you can refer to WordPress Post Types Codex and add more possibilities to your custom post type.

Add Categories Support to Custom Post Types

Categories are a built-in taxonomy in WordPress used to group content. They are utilized by almost every WordPress site, while the pity is that they are only available for posts by default. WordPress pages and custom post types do not support categories.

There are indeed cases that you want to categorize the contents in a custom post type, especially when too many contents have been added. So in below, we will introduce two easy ways to add categories support to custom post types in WordPress. Which way to choose depends on the real condition of your WordPress site.

Add Categories Support with Custom Post Type UI

This method is the suitable option if your custom post types are created with a popular plugin named Custom Post Type UI. As the plugin comes with an option for connecting a post type with any custom taxonomies or built-in taxonomies including categories, you can add the categories support easily by ticking a simple checkbox.

Assumed that you have installed the plugin and created custom post types with it, now you can go to the Add/Edit Post Types submenu under CPT UI in the WordPress dashboard, open the “Edit Post Types” tab, and then select the post type that you want to add categories support to.

Edit Post Types

On the settings page of the post type, scroll the screen down until you see a section for “Built-in Taxonomies”. In the content box, all the available taxonomies are listed one by one. Now, tick the checkbox before “Categories”, and then click “Save Post Type” to get the settings stored.

Add Categories Support to the Custom Post Type

After the changes are saved, you will see a “Categories” option appearing for the custom post type.

Categories

If you also want to add the support for other taxonomies like tags or a custom one, just do the same things as you have done with categories.

Add Categories Support to Custom Post Types Manually

The manual method is recommended if you are in one the following two situations.

  • You have added custom post types manually with the register_post_type function and inserted code in the functions.php file of your theme.
  • The plugin you use to create custom post types does not support categories.

In the former case, you only need to add the following line of code to your custom post type and locate it just after the custom options. This code will add the support for categories automatically.

Taxonomies

When checking through your code, you may find that the “taxonomies” line has already existed with another taxonomy defined. If this is true, you can add “category” next to the taxonomy and separate them with a comma.

Add Categories

In the latter case that you are using a plugin which defines the register_post_type function with no support for categories and does not allow you to make any modification, you can add the following code in the functions.php file.

Add Categories Support

Note that you have to replace “movies” with your own post type key which can be found in the URL of your custom post types.

Post Type Key

Leave a Reply

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