Skip to content

Instantly share code, notes, and snippets.

@ebi3102
Last active April 4, 2018 14:20
Show Gist options
  • Save ebi3102/33bb5a08d65842bf6892b6a12574738e to your computer and use it in GitHub Desktop.
Save ebi3102/33bb5a08d65842bf6892b6a12574738e to your computer and use it in GitHub Desktop.
this snippet code is about adding custom post-type and custom taxonomy in WordPress theme and use in function.php
<?php
//Creat a new taxonomy Booking Categories
function sin_taxo(){
register_taxonomy( 'booking_category', 'booking',
array(
'labels' => array(
'name' => __('Booking Categories'),
'singular_name' => __('Booking Category'),
'add_new' => _x('Add New Category' , 'booking-category'),
'add_new_item' => __('Add New Category'),
'search_item' => __('Search Booking Category'),
'all_items' => __('All Booking Categories'),
'parent_item' => __('Parent Booking Category'),
'parent_item_colon' => __('Parent Booking Category')
),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'rewrite' => array('slug' => 'booking-category'),
'capabilities' => array(
'manage_terms' => 'manage_categories',
'edit_terms' => 'edit_categories',
'delete_terms' => 'delete_categories',
'assign_terms' => 'assign_categories',
),
'show_in_rest' => true,
'rest_base' => 'categories',
'rest_controller_class' => 'WP_REST_Terms_Controller',
));
}
add_action('init', 'sin_taxo');
//Add Booking post_type
function booking_post_type() {
register_post_type('booking' ,
array(
'labels' => array(
'name' => __('Bookings'),
'add_new' => _x('Add New' , 'booking'),
'add_new_item' => __('Add New Booking'),
'all_items' => __('All Bookings')
),
'public' => true,
'has_archive' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-calendar-alt',
'capabilities' => array(
'edit_post' => 'edit_booking',
'read_post' => 'read_booking',
'delete_post' => 'delete_booking',
),
add_post_type_support('booking' ,
array(
'title','editor','author','excerpt','trackbacks','custom-fields','comments','revisions', 'thumbnail')
),
'taxonomies' => array(booking_category , post_tag),
'has_archive' => true,
'rewrite' => array(
'slug' => 'bookings',
'with_front' => true,
'feeds' => true,
'pages' => true,
),
)
);
}
add_action('init', 'booking_post_type');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment