{"id":1084,"date":"2018-01-31T11:26:40","date_gmt":"2018-01-31T11:26:40","guid":{"rendered":"https:\/\/firstsiteguide.com\/create-custom-post-types\/"},"modified":"2023-10-04T09:28:26","modified_gmt":"2023-10-04T09:28:26","slug":"wordpress-custom-post-types","status":"publish","type":"post","link":"https:\/\/firstsiteguide.com\/wordpress-custom-post-types\/","title":{"rendered":"How to Create Custom Post Types in WordPress","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"
Before we actually show you how to create your own custom post type which you’ll be proudly using on your new WordPress powered blog<\/a>, let’s see what a custom post type actually is.<\/p>\n\n\n\n A post type is simply a set of rules which are used to describe the way content is presented in your article. Each post type has its own parameters which define it so you can tell a difference between a post, page, archive, revision or a navigation menu<\/a>. But as you will see, if you start writing articles as your posts, everything you write will have the same structure. That\u2019s because you will use the same template for the post. But that is completely OK if you write a blog where one post type is enough to handle your articles.<\/p>\n\n\n\n Through the not so long history, WordPress has evolved tremendously and it has definitely outgrown its role as a blog platform<\/a>. It has become one of the most used and appreciated content management systems in the world. Allowing people to create custom post types is one of the main reasons for that.<\/p>\n\n\n\n Let’s see what a custom post type can do for you in a simple example. Imagine you are running a gaming website. You want to publish news on a regular basis, there are numerous trailers published every day which you can share with your audience, your authors play new games and write reviews, you want to publish screenshots from your latest online match, etc.<\/p>\n\n\n\n As you can already guess, there are several content types you would need in this case and if you continue on using regular posts, all of the content will look the same and it will make it harder for you and for your visitors to find a difference between a video article and a review. Yes, you want a custom post type to make everything look more organized.<\/p>\n\n\n\n Stay with that picture just for a few more seconds. If you create a custom post type, your news could have a special area where you can place a link to the source. Your game review post type could have a rating the author gave to a certain game including a star-based system, and you can apply different styling for, let’s say, the subtitle of your review. Your trailers post type would accentuate a video and let people enjoy it from a lightbox instead of viewing it in a post. We can go on forever, but you get the point, right?<\/p>\n\n\n\n OK, we know you are getting bored with our talk \u2013 you are here to learn how to create a custom post so let’s start. Stretch your muscles, take a deep breath and when you are ready, let’s start. If you’re interested in digging deeper into WordPress<\/a> and the code, skip to the plugin that will help you<\/a>.<\/p>\n\n\n\n Make sure the code is placed before the closing PHP tag (?>) or it won’t work.<\/p>\n\n\nCreate a Custom Post Type<\/h2>\n\n\n\n
\n
\/\/ Creates Game Reviews Custom Post Type
function game_reviews_init() {
$args = array(
'label' => 'Game Reviews',
'public' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => false,
'rewrite' => array('slug' => 'game-reviews'),
'query_var' => true,
'menu_icon' => 'dashicons-video-alt',
'supports' => array(
'title',
'editor',
'excerpt',
'trackbacks',
'custom-fields',
'comments',
'revisions',
'thumbnail',
'author',
'page-attributes',)
);
register_post_type( 'game-reviews', $args );
}
add_action( 'init', 'game_reviews_init' );<\/pre>\n\n<\/div>\n\n\n<\/pre>\n\n\n\n