Add custom post type with add category option on wordpress

Use the following code on WordPress websites to Add custom post type with add category option

function services() {
register_post_type( 'services',
// CPT Options
array(
'labels' => array(
'name' => __( 'services' ),
'singular_name' => __( 'services' )
),
'public' => true,
'has_archive' => false,
'rewrite' => array('slug' => 'services'),
#'supports' => array( 'title', 'editor', 'thumbnail' ),
'supports' => array( '' ),
)
);
}
// Hooking up our function to theme setup
add_action( 'init', 'services' );
register_taxonomy(
"service_categories",
array("services"),
array("hierarchical" => true,
"label" => "Categories",
"singular_label" => "Category",
"rewrite" =>
array(
'slug' => 'services',
'with_front'=> false )
)
);

Leave a Reply