Custom Post Type With Taxonomy

Divi WordPress Theme

Custom post type is a  new post type of wordpress. You can open your theme folder and function.php and added below this code for custom post type.

add_action('init', 'cl_service');

function cl_service() {
    $labels = array(
        'name' => 'Service',
        'singular_name' => 'Service',
        'menu_name' => 'Services',
        'name_admin_bar' => 'Services',
        'add_new' => 'Add New',
        'add_new_item' => 'Add New Service',
        'new_item' => 'New Service',
        'edit_item' => 'Edit Service',
        'view_item' => 'View Service',
        'all_items' => 'All Services',
        'search_items' => 'Search Service',
        'parent_item_colon' => 'Parent Service:',
        'not_found' => 'No Service found.',
        'not_found_in_trash' => 'No Service found in Trash.'

    $args = array(
        'labels' => $labels,
        'public' => true,
        'rewrite' => array('slug' => 'cl-services'),
        'has_archive' => true,
        'menu_position' => 21,
        'menu_icon' => 'dashicons-hammer',
        'supports' => array('title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields')
    register_post_type('cl_service', $args);

Custom taxonomy is a category of custom post type in wordpress. Open your theme function.php and added below this code.

function cl_taxonomies_service() {
    $labels = array(
        'name' => _x('Service Categories', 'taxonomy general name'),
        'singular_name' => _x('Service Category', 'taxonomy singular name'),
        'search_items' => __('Search Service Categories'),
        'all_items' => __('All Service Categories'),
        'parent_item' => __('Parent Service Category'),
        'parent_item_colon' => __('Parent Service Category:'),
        'edit_item' => __('Edit Service Category'),
        'update_item' => __('Update Service Category'),
        'add_new_item' => __('Add New Service Category'),
        'new_item_name' => __('New Service Category'),
        'menu_name' => __('Service Categories'),

    $args = array(
        'labels' => $labels,
        'hierarchical' => true,
    register_taxonomy('Service_category', 'cl_service', $args);

add_action('init', 'cl_taxonomies_service', 0);

Thanks for your trying…

Khandoker Hirok

I'm an expert web developer over 6 years experience. I can fix bugs, customize and makes website and Software as per your requirements with Wordpress, PHP, Laravel and Codeigniter. My Fiverr: https://fiverr.com/hirokbd

Related Articles

Leave a Reply

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

Back to top button