By default, WordPress comes with post and pages as the main content types. However, we can create our custom content type, and these custom content types are referred to as WordPress custom Post Types. In this article, we will create a custom post type and a template to display it.

Why you should use WordPress Custom Post type

Let’s take a look at a real-life example. We want to run a blog where we would publish movie reviews among posts. We would like to add features for every movie, make it searchable by actors’ names, genres, etc. This is when we will need to create a custom post type for movies and add custom taxonomy for genres and actors. You can make custom post type with a plugin or custom it in your theme functions.php file. 

If you are going with the plugin, the first thing you need to do is install and activate WordPress Custom Post Type UI plugin. Now go to CPT UI –> Add New to create a new custom post type.

WordPress Custom Post Type Kontra agency example

First, you need to provide your post slug/name which will be used as the link to your post archive ( Next field will be your label name, and this will be visible in your WordPress dashboard.  The problem with using a plugin is that your custom post types will disappear when the plugin is deactivated. Any data you have in those custom post types will still be there, but your custom post type will be unregistered and will not be accessible from the admin area.

If you are making a custom theme or know how functions.php works, its best to make custom post types that way. Let’s take a look at a minimal working example to help you understand how it works.

// Our custom post type function
function create_posttype() {
    register_post_type( 'movies',
    // CPT Options
            'labels' => array(
                'name' => __( 'Movies' ),
                'singular_name' => __( 'Movie' )
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'movies'),
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

What this code does is registering a post type ‘movies’ with an array of arguments. Arguments consist of all of our options for a custom post type. This array consists of two parts: the first which is labels and the second part which includes options like public visibility, has an archive, and slug that will be used in URLs for this post type

Now when you’ve registered your WordPress custom post type, you should have it visible in your admin menu. Lastly, besides using custom fields which we already learned, the only thing left is to register taxonomies genre and actors.

Display Custom post type

WordPress comes with built-in support for displaying your custom post types. Once you have added a few items into your new custom post type, it is time to display them on your website. You can preview your archive of custom posts with archive link registered ( If you don’t have a custom template named archive-movies.php, WordPress will use the default archive.php template. And to showcase your new custom post, you can make a single-movies.php template which can also be additionally customized. If you want to query posts form your custom post type in any of the templates, you can do it by calling WP_Query.

These custom queries come really handy when you start creating custom templates. Hope that even if this seems difficult to you, give custom posts a try with a plugin and when you figure out all the setting start with coding it in functions.php


Ivan Jurković

Front-end web developer at Kontra and a car enthusiast.