Create WordPress Custom Post Types
Do you want to learn how to create WordPress Custom Post Types?
Custom post types convert a blogging platform into a super-powerful CMS. By using WordPress Custom Post Types you can make any type of website.
Today, In this article, I’ll show you how to create very easy way WordPress Custom Post Types and how to display them.
When you instill WordPress, You will only see three default built-in content types on the website admin panel, like: posts, pages, and media. You will think, that this is not enough for your website.
So, You will depend on the third-party plugins. A plugin can your website super slow.
However, Today WordPress has become malleable and advanced. You can make your website more attractive and you can add more content, and images using WordPress Custom Post Types functions.
Also, you can create as many Custom Post Types as you want. In this context, I will show you how to create custom post types in WordPress and I will also show you how to display custom post types on your website front-end.
What is Custom Post Type in WordPress?
Very simple question, WordPress Custom Post Types are content types e.g posts and pages.
According to Codex, Custom Post Types are also known as Custom Content Types that can add to your WordPress website using a function called the register_post_type(). Here, By default, WordPress post types:
- Post
- Page
- Attachment
- Revision
- Navigation Menu
You may need to create Custom Post Types e.g, Portfolio, Testimonials, Products, etc.
When do I need a custom post type?
You would possibly work with WordPress custom post types When working with WordPress. You can make a beautiful and professional WordPress website using the WordPress default options. But, if you want to create additional fields to enter more information with your content, your need to create WordPress custom post types.
You can create WordPress custom post types for creating additional fields. You can create custom post types for displaying extra information on your product page, checkout page, account page, etc.
You can display that particular content differently from posts or pages.
Create WordPress Custom Post Type
First, I would like to show you a quick fully Custom Post Types working example that you interpret how it works.
I will use WordPress action hook add_action( ‘init’, ‘custom_post_type’ ), custom_post_type() your function name. Learn more here WordPress init Hook Developer Resources
I have created movies post types with an array of arguments. So, You can create a post type e.g news, portfolio, etc. And last part contains other arguments like public visibility, has an archive, and slug that will be used in URLs for this post type.
Now, let’s create a custom post type for your WordPress Theme. Add the following piece of code in your active theme function.php file below.
After adding this code you will see your dashboard Movies menu in the left sidebar under the post menu. Like the following attached.
Displaying WordPress Custom Post Types On The Front Page
Display WordPress Custom Post Types on the website. If you would like them to display among your regular post, then add this code in your functions.php file.
Querying Custom Post Types
If you are recognizable with the coding and if you would like to run loop queries in your templates, then this code will help you.
Custom Taxonomies For Custom Post Types
If you would like to learn, What is a Taxonomy? or How To Create Custom Taxonomies In WordPress, then please check this article.
Because of this tutorial, I wouldn’t mention again the detailed WordPress Taxonomy. However, In this context, I would like to show you,
Create Custom Taxonomies for the WordPress Custom Post Types. So, Let’s start,
After adding this code, You will see in your website admin dashboard, that a new dropdown menu tab, looks like the following attached.
So, now you can add the category for your Custom Post Types.
Add Post Meta Boxes
If you would like to sell your products online, you may need to add products price and descriptions.
So, You can add very easy these fields using the WordPress Meta box. So, I will help you in creating a custom meta box for WordPress Custom Post Types.
Step 1: Create a Meta Box
Add the following code in your active theme functions.php file.
The above code creates the meta box with the following parameters:
- The Meta box Title visible for the users (A title should be unique).
- The function will display the contents of the meta box.
- The post type the meta box belongs to.
- The priority of the meta box (how “high” and “side” it is displayed).
Step 2: Add a Field
Add the following code in your active theme functions.php file.
Step 3: Save Data
Add the following code in your active theme functions.php file.
A Simple post meta box creating is done. So, you should display this box on your website. Also, you can display it anywhere.
Now, I am going to show you, how to display a custom meta box on the WordPress Website. Meta-data can be display easily using the WordPress get_post_meta() function.
I hope In this article, you learned, Create WordPress Custom post types, Custom Taxonomies For Custom Post Types, and how to add Post Meta Boxes to the WordPress Website.
if you have any questions, please comment below.
WordPress Custom Post Types Best Plugins
If you want to create WordPress custom post types using a plugin. Below a list of the premium and free WordPress custom post types plugins.
Conclusion
WordPress Custom Post Types is very important for your website. You can create a gallery page, FAQ, Product Review, Recipe Review, and other essential pages using the WordPress Custom Post Types.
You can manage your website using the meta box or post type Or you can write your own plugin using the WordPress register_post_type() function. Really If you enjoyed this article, please share it.
WordPress Website Development Services
If you want to create a WordPress website or eCommerce website, kindly visit our service.
- Responsive WordPress Website
- eCommerce Website With WooCommerce
- WordPress Speed Optimization
- WordPress Website Security
- WordPress SEO
Please Visit Service: WordPress Website Development Services
Please check my Fiverr Profile. To Check: Create an eCommerce Website Or Customize WordPress Website