Read This Offline With Code With Me APP

Add custom post type in wordpress

Posted On: Jun 17, 2015

WordPress can hold and display many different types of content. A single item of such a content is generally called a post, although post is also a specific post type. Internally, all the post types are stored in the same place, in the wp_posts database table, but are differentiated by a column called post_type Wordpress has two post types by default: post and page. Consider a situation, if you are building a website which specific content type, suppose Blog, News, reservation or any custom content then you need to create a custom post type Custom post type can be create by simple hook:  
add_action( hook, method);
Here we are going to use init hook and my_custom_post_reservation_items method Open functions.php and add following code to make custom reservation post type.
//make custom post type

function my_custom_post_reservation_items() {
    $labels = array(
        'name'               => _x( 'Reservations', 'post type general name' ),
        'singular_name'      => _x( 'Reservation', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'book' ),
        'add_new_item'       => __( 'Add New Reservation' ),
        'edit_item'          => __( 'Edit Reservation Items' ),
        'new_item'           => __( 'New Reservation Items' ),
        'all_items'          => __( 'All Reservations' ),
        'view_item'          => __( 'View Reservation Items' ),
        'search_items'       => __( 'Search Reservation Items' ),
        'not_found'          => __( 'No Reservation Items found' ),
        'not_found_in_trash' => __( 'No Reservation Items found in the Trash' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'Reservation',
        'taxonomy'           =>'Category'
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our Reservation data',
        'public'        => true,
        'menu_position' => 2,
        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,
        'taxonomies' => array('category')
    register_post_type( 'reservation', $args ); 
    //remove_post_type_support('rent_items', 'editor' );

add_action( 'init', 'my_custom_post_reservation_items');


  • hook
  • posttype
  • wordpress

Share This On

By Shiva Sharma On Jun 24, 2015

Nice Article