12 Most Useful WordPress Custom Post Types Tutorials

Would you like to learn more about custom post types?

WordPress allows you to create custom types of content. Besides posts and pages, you might like to add other types of content to your website, such as products, reviews, or recipes.

In this article, we will share the 12 most useful WordPress custom post types tutorials.

12 Most Useful WordPress Custom Post Types Tutorials

What Are Custom Post Types in WordPress?

Custom post types are a type of content on your WordPress site that are not the default posts and pages. Custom post types are often added to a WordPress site using custom code or plugins.

For example, you can create custom post types for portfolios, testimonials, and products. Many WordPress plugins also use custom post types to store data on your website.

How can you use custom post types on your WordPress website?

As the largest free WordPress resource site for beginners, we’ve written a lot about custom post types over the years. Let’s take a look at the most useful custom post types tutorials here on WPBeginner.

1. Decide Whether You Need A Custom Post Type

Before you start creating custom post types or taxonomies on your WordPress site, it’s important to evaluate your needs. A lot of times you can get the same results with the default WordPress posts and pages.

With the help of built-in categories and tags, you can sort your content in many different ways. For example, with pages, you can set up a hierarchical layout of content with child pages. You can also set up subcategories.

Using the default WordPress features makes content management easier in many ways. For example, a custom post type wouldn’t appear on your blog page or in your post RSS feeds.

After looking at the default options, you may find that you don’t need custom post types after all.

If you are unsure, then refer to this guide about when you need a custom post type or taxonomy in WordPress.

2. Create Custom Post Types in WordPress

Once you decide that you do need a custom post type, you’ll need to create it. You can do this with a plugin, or manually by using code.

The Custom Post Type UI plugin makes it easy to create custom post types and is recommended for most users. You do this from the ‘Edit/Add Post Types’ page.

Create a New Custom Post Type With a Plugin

Alternatively, you can add a custom post type by pasting a code snippet into your theme’s functions.php file. The advantage of this method is your custom post types won’t disappear if the plugin is deactivated, but it’s only suitable if you’re comfortable handling code.

To learn more, see our guide on how to create custom post types in WordPress.

3. Create a Custom Post Types Archive Page

Adding custom post types in WordPress has become very easy thanks to the Custom Post Type UI plugin. However, many beginners have trouble displaying them on their websites.

To add a custom post type archive page, you first need to make sure that archives are enabled for your custom post type. In most cases they are, but if not then you can enable them in Custom Post Type UI’s advanced options or by using code.

CPT UI turn on archive

Now you can visit the custom post type archive page. Let’s say your custom post type is called ‘movies’ and you have SEO friendly permalinks enabled. Then your post type archive will be located at:

http://www.example.com/movies/

You’ll need to replace ‘example.com’ with your own domain name, and ‘movies’ with your custom post type name.

You can now add this archive page to your navigation menu. You can also customize it by adding a custom template to your WordPress theme or using a theme builder like SeedProd.

Edit your post type page

We show you how to do all of these things step by step in our guide on how to create a custom post types archive page in WordPress.

4. Add Custom Post Types to Your Main RSS Feed

By default, WordPress only includes your blog posts in your site’s main RSS feed. This means that your custom post type content won’t be visible to your main RSS feed subscribers.

You can easily include all publicly available post types into your main RSS feed by adding the following code to your theme’s functions.php file or a site-specific plugin.

function myfeed_request($qv) {
if (isset($qv['feed']))
$qv['post_type'] = get_post_types();
return $qv;
}
add_filter('request', 'myfeed_request');

However, you can use a different code snippet to only include specific custom post types.

For more detail on both methods, see our guide on how to add custom post types to your main WordPress RSS feed.

5. Make a Separate RSS Feed for Each Custom Post Type

WordPress automatically generates separate RSS feeds for different archive pages of your website, including custom post types.

Let’s say you have a custom post type called ‘movies’ on your website. We’ve already seen that you can view all content created in that post type by visiting the post type archive page.

https://example.com/movies

To view the RSS feed, all you need to do is add /feed/ to the custom post type archive URL.

https://example.com/movies/feed/

Alternately, you can also view the feed by adding the post type parameter to your main WordPress RSS feed. For example:

https://example.com/feed/?post_type=movies

Now that you know how to access the RSS feeds for any custom post type on your website, you can use that URL to create links to your custom post type feeds.

For instance, you may want to display an icon or plain text link on the custom post type archive page, so that your visitors can easily subscribe to those posts.

To learn how to do that, see our guide on how to make a separate RSS feed for each custom post type in WordPress.

6. Include Custom Post Types in Search Results

By default, WordPress will never show custom post types in its on-site search results. That means your visitors may miss out on some great content, and you’ll miss out on extra page views.

The easiest way to include custom post types in WordPress search is with the SearchWP plugin. It’s easy to use and lets you search content that isn’t included in the default WordPress search.

To include custom post types in your searches, simply click on the plugin’s ‘Sources & Settings’ button. Here you can put a checkmark next to each post type you wish to include in search results.

Including custom post types in WordPress search

You can also choose how important each custom post type is when displaying search results, and customize the search engine in other ways.

To learn how, see our step by step guide on how to include custom post types in WordPress search results.

7. Create a Search Form for Custom Post Types

You can also create a custom search form that will only show results from your custom post type. For example, if you have a custom post type called ‘movies’, then you can create a special movie search form that only returns movies in the search results.

This kind of custom search helps your visitors view more pages and spend more time on your website. This will give off positive WordPress SEO signals like lower bounce rate and increased dwell time.

You can create an advanced search form for custom post types using the SearchWP plugin. It allows you to create a second search engine that will only search your custom post type. You can then create a custom search form that you can add to your posts or sidebar.

For more details, see our guide on how to create an advanced search form in WordPress for custom post types.

8. Add Categories to a Custom Post Type

By default, WordPress categories can only be used to organize posts, not custom post types.

You could create a custom taxonomy to organize your custom posts, but what if you want to use the same categories you use for your blog posts?

The easiest way to associate your custom post type with categories is the Custom Post Type UI plugin. It adds a ’Taxonomies’ area in the settings for each custom post type.

Allowing Custom Post Types to Use Categories

Simply check the ‘Categories (WP Core)’ box and you will be able to use categories to organize your custom post types.

See our guide on how to add categories to a custom post type in WordPress to learn more.

9. Add Sticky Posts for Custom Post Types

The sticky posts feature in WordPress allows you to add featured posts. By default, it only works for blog posts and not for custom post types.

You can enable sticky posts for your custom post types as well by installing the Sticky Posts – Switch plugin. You simply check the box next to the custom post types that you wish to support this feature.

Visit the Settings » Sticky Posts - Switch Page to Configure the Plugin

Now when you visit the admin page for that custom post type, you will notice a new column where you can make posts sticky.

All you need to do is click the star next to the posts you wish to feature.

Click the Star Next to the Posts You Wish to Make Sticky

These sticky posts will be shown on your WordPress home page. To display sticky posts on your custom post type archive page as well, you’ll need to add some code to your theme files.

You’ll find all the details in our guide on how to add sticky posts in WordPress custom post type archives.

10. Add User Submitted Content to Custom Post Types

You may want to allow users to submit content for custom post types on your site, such as movie reviews or recipes. This is an easy way of adding extra content to your site.

One way to do this is by giving users access to your WordPress admin area and assigning them the author user role. Alternatively, you can add a submission form to your website.

You can do that using the WPForms plugin. You will need the Pro version to access the post submissions addon, and the provided ‘Blog Post Submission Form’ template makes creating the form simple.

By default, user submitted posts are saved as ‘Drafts’ pending review. You can change the post type in the form’s settings so content is submitted to a custom post type instead.

For more details, see our guide on how to allow users to submit posts to your WordPress site.

11. Switch or Convert Custom Post Types

You may come across situations where you will have to merge or convert custom post types. For example, you may want to move items from one post type to another.

Simply install and activate the Post Type Switcher plugin. Upon activation, you should go to the custom post type admin page and select the posts you want to move.

When you bulk edit the posts, you will notice there is a new drop down menu allowing you to change the post type for that item.

You can learn more in our guide on how to switch or convert custom post types in WordPress.

12. Add Custom Meta Boxes for Post Types

Custom meta boxes allow you to add custom fields to the WordPress post editor screen. This way you can create additional input fields for your post types.

The easiest way to create custom meta fields in WordPress is by using the Advanced Custom Fields plugin. Simply click the ‘Add New’ button on the Custom Fields page.

After that, you should follow the on-screen instructions to create a group of custom fields to add to your custom post type.

For further details, see our step by step guide on how to add custom meta boxes in WordPress posts and post types.

We hope this tutorial helped you learn some cool tricks for custom post types in WordPress. You may also want to see our ultimate WordPress security guide, or check out our list of tips on how to speed up WordPress performance.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post 12 Most Useful WordPress Custom Post Types Tutorials first appeared on WPBeginner.

How to Create Custom Post Types in WordPress

Do you want to learn how to easily create custom post types in WordPress? Custom post types transform a WordPress site from a blogging platform into a powerful Content Management System (CMS).

Basically, they allow you to go beyond posts and pages by creating different content types for your website.

In this article, we’ll show you how to easily create custom post types in WordPress. We’ll teach you two methods and you can choose one that looks easier to you.

Creating custom post types in WordPress

What is Custom Post Type in WordPress?

Custom post types are content types like posts and pages. Since WordPress evolved from a simple blogging platform into a robust CMS, the term post stuck to it. However, a post type can be any kind of content.

By default, WordPress comes with these post types:

  • Post
  • Page
  • Attachment
  • Revision
  • Nav Menu

You can create your own custom post types and call them whatever you want.

For instance, if you run a movie review website, then you would probably want to create a movie reviews post type. This post type can have different custom fields and even its own custom category structure.

Other examples of post types are Portfolio, Testimonials, Products, etc.

Many popular WordPress plugins already use custom post types to store data on your WordPress website. The following are a few top plugins that use custom post types.

  • WooCommerce – Adds a product custom post type to your WordPress site.
  • WPForms – Creates a wpforms post type to store all your forms
  • MemberPress – Adds a memberpressproduct custom post type

When do I need a custom post type?

Check out our article about when do you really need custom post types or taxonomies in WordPress.

Also take a look at WPBeginner’s Deals and Glossary sections. These are custom post types that we created to keep these sections separate from our daily blog articles. It helps us better organize our website content.

You will also notice that we are using custom taxonomies for them instead of categories or tags.

That being said, let’s take a look at how to easily create custom post types in WordPress for your own use.

Method 1. Creating a Custom Post Type – The Easy Way

The easiest way to create a custom post type in WordPress is by using a plugin. This method is recommended for beginners because it is safe and super easy.

The first thing you need to do is install and activate the Custom Post Type UI plugin. Upon activation, the plugin will add a new menu item in your WordPress admin menu called CPT UI.

Now go to CPT UI » Add New to create a new custom post type.

Add new custom post type

First, you need to provide a slug for your custom post type. This slug will be used in the URL and in WordPress queries, so it can only contain letters and numbers.

Below that, you need to provide the plural and singular names for your custom post type.

Next, you can optionally click on the link that says ‘Populate additional labels based on chosen labels’. Doing so will fill in the rest of the label fields down below.

Scroll down to the ‘Additional Labels’ section and from here you can provide a description for your post type and change labels.

Post type labels

Labels will be used throughout the WordPress user interface when you are managing content in that particular post type.

Next, comes the post type settings option. From here you can set up different attributes for your post type. Each option comes with a brief description explaining what it does.

Post type settings

For instance, you can choose not to make a post type hierarchical like pages or reverse chronological like posts.

Below the general settings, you will see the option to select which editing features this post type would support. Simply check the options that you want to be included.

Supported options

Finally, click on the ‘Add Post Type’ button to save and create your custom post type.

That’s all, you have successfully created your custom post type. You can go ahead and start adding content.

We will show you how to display your custom post type on your website later in this article.

Creating a Custom Post Type Manually

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 working on a client site and do not want to install another plugin, then you can manually create your custom post type by adding the required code in your theme’s functions.php file or in a site-specific plugin (See: Custom Post Types Debate functions.php or Plugin).

First, we will show you a quick and fully working example so that you understand how it works. Take a look at this code:

// Our custom post type function
function create_posttype() {

	register_post_type( 'movies',
	// CPT Options
		array(
			'labels' => array(
				'name' => __( 'Movies' ),
				'singular_name' => __( 'Movie' )
			),
			'public' => true,
			'has_archive' => true,
			'rewrite' => array('slug' => 'movies'),
			'show_in_rest' => true,

		)
	);
}
// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

What this code does is that it registers a post type 'movies' with an array of arguments. These arguments are the options of our custom post type.

This array has two parts, the first part is labeled, which itself is an array. The second part contains other arguments like public visibility, has archive, slug, and show_in_rest enables block editor support.

Now let’s take a look at a detailed piece of code that adds more options to your custom post type.


/*
* Creating a function to create our CPT
*/

function custom_post_type() {

// Set UI labels for Custom Post Type
	$labels = array(
		'name'                => _x( 'Movies', 'Post Type General Name', 'twentytwenty' ),
		'singular_name'       => _x( 'Movie', 'Post Type Singular Name', 'twentytwenty' ),
		'menu_name'           => __( 'Movies', 'twentytwenty' ),
		'parent_item_colon'   => __( 'Parent Movie', 'twentytwenty' ),
		'all_items'           => __( 'All Movies', 'twentytwenty' ),
		'view_item'           => __( 'View Movie', 'twentytwenty' ),
		'add_new_item'        => __( 'Add New Movie', 'twentytwenty' ),
		'add_new'             => __( 'Add New', 'twentytwenty' ),
		'edit_item'           => __( 'Edit Movie', 'twentytwenty' ),
		'update_item'         => __( 'Update Movie', 'twentytwenty' ),
		'search_items'        => __( 'Search Movie', 'twentytwenty' ),
		'not_found'           => __( 'Not Found', 'twentytwenty' ),
		'not_found_in_trash'  => __( 'Not found in Trash', 'twentytwenty' ),
	);
	
// Set other options for Custom Post Type
	
	$args = array(
		'label'               => __( 'movies', 'twentytwenty' ),
		'description'         => __( 'Movie news and reviews', 'twentytwenty' ),
		'labels'              => $labels,
		// Features this CPT supports in Post Editor
		'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
		// You can associate this CPT with a taxonomy or custom taxonomy. 
		'taxonomies'          => array( 'genres' ),
		/* A hierarchical CPT is like Pages and can have
		* Parent and child items. A non-hierarchical CPT
		* is like Posts.
		*/	
		'hierarchical'        => false,
		'public'              => true,
		'show_ui'             => true,
		'show_in_menu'        => true,
		'show_in_nav_menus'   => true,
		'show_in_admin_bar'   => true,
		'menu_position'       => 5,
		'can_export'          => true,
		'has_archive'         => true,
		'exclude_from_search' => false,
		'publicly_queryable'  => true,
		'capability_type'     => 'post',
		'show_in_rest' => true,

	);
	
	// Registering your Custom Post Type
	register_post_type( 'movies', $args );

}

/* Hook into the 'init' action so that the function
* Containing our post type registration is not 
* unnecessarily executed. 
*/

add_action( 'init', 'custom_post_type', 0 );

As you can see, we have added many more options to the custom post type with this code. It will add more features like support for revisions, featured image, custom fields, and more.

We have also associated this custom post type with a custom taxonomy called genres.

You may also notice the part where we have set the hierarchical value to be false. If you would like your custom post type to behave like Pages, then you can set this value to true.

Another thing to be noticed is the repeated usage of twentytwenty string, this is called text-domain. If your theme is translation ready, and you want your custom post types to be translated, then you will need to mention text domain used by your theme.

You can find your theme’s text domain inside style.css file in your theme directory. The text domain will be mentioned in the header of the file.

Displaying Custom Post Types on Your Site

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.

There are a couple of methods that you can use, each one has its own benefits.

Displaying Custom Post Type Using Default Archive Template

First, you can simply go to Appearance » Menus and add a custom link to your menu. This custom link is the link to your custom post type.

Add post type to your navigation menu

If you are using SEO friendly permalinks then your CPT’s URL will most likely be something like this:

http://example.com/movies

If you are not using SEO friendly permalinks, then your custom post type URL will be something like this:

http://example.com/?post_type=movies

Don’t forget to replace example.com with your own domain name and movies with your custom post type name.

Save your menu and then visit the front-end of your website. You will see the new menu you added, and when you click on it, it will display your custom post type archive page using the archive.php template file in your theme.

Using Custom Templates for CPT Archives and Single Entries

If you don’t like the appearance of the archive page for your custom post type, then you can use dedicated template for custom post type archive.

To do that all you need to do is create a new file in your theme directory and name it archive-movies.php. Replace movies with the name of your custom post type.

For getting started, you can copy the contents of your theme’s archive.php file into archive-movies.php template and then start modifying it to meet your needs.

Now whenever the archive page for your custom post type is accessed, this template will be used to display it.

Similarly, you can also create a custom template for your post type’s single entry display. To do that you need to create single-movies.php in your theme directory. Don’t forget to replace movies with the name of your custom post type.

You can get started by copying the contents of your theme’s single.php template into single-movies.php template and then start modifying it to meet your needs.

Displaying Custom Post Types on The Front Page

One advantage of using custom post types is that it keeps your custom content types away from your regular posts. However, if you would like them to display among your regular post, then you can do so by adding this code into your theme’s functions.php file or a site-specific plugin:

add_action( 'pre_get_posts', 'add_my_post_types_to_query' );

function add_my_post_types_to_query( $query ) {
	if ( is_home() && $query->is_main_query() )
		$query->set( 'post_type', array( 'post', 'movies' ) );
	return $query;
}

Don’t forget to replace movies with your custom post type.

Querying Custom Post Types

If you are familiar with the coding and would like to run loop queries in your templates, then here is how to do that (Related: What is a Loop?).

By querying the database, you can retrieve items from a custom post type.

<?php 
$args = array( 'post_type' => 'movies', 'posts_per_page' => 10 );
$the_query = new WP_Query( $args ); 
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<div class="entry-content">
<?php the_content(); ?> 
</div>
<?php wp_reset_postdata(); ?>
<?php else:  ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>

In this code, first, we have defined the post type and posts per page in the arguments for our new WP_Query class.

After that, we ran our query, retrieved the posts and displayed them inside the loop.

Displaying Custom Post Types in Widgets

You will notice that there is a default widget in WordPress to display recent posts, but it does not allow you to choose a custom post type.

What if you wanted to display the latest entries from your newly created post type in a widget? There is an easy way to do this.

First thing you need to do is install and activate the Ultimate Posts Widget plugin. Upon activation, simply go to Appearance » Widgets and drag and drop the Ultimate Posts widget to a sidebar.

Ultimate posts widget

This powerful widget will allow you to show recent posts from any post types. You can also display post excerpts with a read more link or even show a featured image next to post title.

Configure the widget by selecting the options you want and by selecting your custom post type. After that save your changes and see the widget in action on your website.

More Advance Custom Post Type Tweaks

There is so much more you can do with your custom post types. You can learn to add your custom post types in main RSS feed or create a separate feed for each custom post type.

For more hacks, see our list of the most useful WordPress custom post types tutorials.

If you’re looking for a no-code solution to customize your custom post type archive pages, then we recommend taking a look at a WordPress page builder plugin like Beaver Builder or Divi because they both can help you do that.

We hope this article helped you learn how to create custom post types in WordPress. You may also want to see our guide on how to increase your website traffic with practical tips.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

The post How to Create Custom Post Types in WordPress appeared first on WPBeginner.