In this tutorial we are going to see how can we add custom post types inside post type or any other custom post type you make. Its very easy and you can extend their limitless functionality.
I am going to Add “Enquiries” Section Inside My Custom Post Type” which will be “Trips”. If you want to add inside existing post type which will be “post” or “page”, just type their names and you are good to go.
Lets get started.
What are we going to do ?
- Write Code for Custom Post Type
- Add an action hook to enable it in your WordPress Admin Dashboard.
Add Custom Post Type in WordPress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
// Create Custom Post Type [ Enquiries ] function cih_create_enquiry_post_type() { $labels = array( 'name' => __( 'All Enquiries' ), 'singular_name' => __( 'Enquiry' ), 'search_items' => __('All Enquiry') ); $args = array( 'labels' => $labels, 'public' => true, 'capability_type' => 'post', 'rewrite' => true, 'public' => false, 'show_ui' => true, 'hirerarchial' => false, 'edit_item' => 'Edit Enquiry', 'new_item' => 'New Enquiry', 'view_item' => 'View Enquiry', 'not_found' => 'No Enquiries found.', 'not_found_in_trash' => 'No Enquiries found in trash.', 'show_in_menu' => 'edit.php?post_type=trips', 'supports' => array( 'title', 'excerpt', 'editor' ) ); register_post_type( 'enquiry', $args); } |
Now finally call the hook that that will enable custom post type in admin dashboard.
1 |
add_action( 'init', 'cih_create_enquiry_post_type' ); |
Note :- Show in Menu indicates that where you want to have your custom post type to be inside. If its removed then new menu is created in admin dashboard as “Enquiry” which will be independent and outside of other menus.
If you want to have your custom post type inside posts section then just change :
'show_in_menu' => 'edit.php?post_type=trips',
TO
'show_in_menu' => 'edit.php?post_type=posts',
OR
'show_in_menu' => 'edit.php?post_type=page',
If you have any problem regarding creating new post types let me know or feel free to comment below.
Leave a Reply