Create The Custom Post Type in WordPress

[et_pb_section bb_built=”1″ admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

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:page,Post,etc..

You can create your own custom post types and call them whatever you want. For example 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,Articles,Property,Car etc.

Creating a Custom Post Type Manually

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:

Function.php

[/et_pb_text][et_pb_code admin_label=”Code”]function custom_post_type() {<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –> $labels = array(<!– [et_pb_line_break_holder] –> 'name' => _x( 'Post Types', 'Post Type General Name', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'singular_name' => _x( 'Post Type', 'Post Type Singular Name', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'menu_name' => __( 'Post Types', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'name_admin_bar' => __( 'Post Type', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'archives' => __( 'Item Archives', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'attributes' => __( 'Item Attributes', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'all_items' => __( 'All Items', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'add_new_item' => __( 'Add New Item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'add_new' => __( 'Add New', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'new_item' => __( 'New Item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'edit_item' => __( 'Edit Item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'update_item' => __( 'Update Item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'view_item' => __( 'View Item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'view_items' => __( 'View Items', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'search_items' => __( 'Search Item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'not_found' => __( 'Not found', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'featured_image' => __( 'Featured Image', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'set_featured_image' => __( 'Set featured image', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'use_featured_image' => __( 'Use as featured image', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'insert_into_item' => __( 'Insert into item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'items_list' => __( 'Items list', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'filter_items_list' => __( 'Filter items list', 'text_domain' ),<!– [et_pb_line_break_holder] –> );<!– [et_pb_line_break_holder] –> $args = array(<!– [et_pb_line_break_holder] –> 'label' => __( 'Post Type', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'description' => __( 'Post Type Description', 'text_domain' ),<!– [et_pb_line_break_holder] –> 'labels' => $labels,<!– [et_pb_line_break_holder] –> 'supports' => array( ),<!– [et_pb_line_break_holder] –> 'taxonomies' => array( 'category', 'post_tag' ),<!– [et_pb_line_break_holder] –> 'hierarchical' => false,<!– [et_pb_line_break_holder] –> 'public' => true,<!– [et_pb_line_break_holder] –> 'show_ui' => true,<!– [et_pb_line_break_holder] –> 'show_in_menu' => true,<!– [et_pb_line_break_holder] –> 'menu_position' => 5,<!– [et_pb_line_break_holder] –> 'show_in_admin_bar' => true,<!– [et_pb_line_break_holder] –> 'show_in_nav_menus' => true,<!– [et_pb_line_break_holder] –> 'can_export' => true,<!– [et_pb_line_break_holder] –> 'has_archive' => true, <!– [et_pb_line_break_holder] –> 'exclude_from_search' => false,<!– [et_pb_line_break_holder] –> 'publicly_queryable' => true,<!– [et_pb_line_break_holder] –> 'capability_type' => 'page',<!– [et_pb_line_break_holder] –> );<!– [et_pb_line_break_holder] –> register_post_type( 'post_type', $args );<!– [et_pb_line_break_holder] –><!– [et_pb_line_break_holder] –>}<!– [et_pb_line_break_holder] –>add_action( 'init', 'custom_post_type', 0 );[/et_pb_code][/et_pb_column][/et_pb_row][/et_pb_section]

Leave a Reply

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