In wordpress add tags and categories to custom post type

In wordpress add tags and categories to custom post type

Many times we use the custom post type in wordpress. Wordpres tutorial, In wordpress add tags and categories to custom post type.  Some times we need to category and tags for custom post type which associated.

In wordpress add tags and categories to custom post type

you can use the following code in functions.php file.

// === CUSTOM POST TYPES === //
function create_my_post_types() {
	register_post_type( 'Services',
		array(
			'labels' => array(
				'name' => __( 'Services' ),
				'singular_name' => __( 'Services' ),
				'add_new_item' => 'Add New Services',
				'edit_item' => 'Edit Services',
				'new_item' => 'New Services',
				'search_items' => 'Search Services',
				'not_found' => 'No Services found',
				'not_found_in_trash' => 'No Services found in trash',
			),
			'_builtin' => false,
			'public' => true,
			'hierarchical' => false,
			'taxonomies' => array( 'website_type', 'service'),
			'supports' => array(
				'title',
				'editor',
				'excerpt',
                                'thumbnail'
			),
			'rewrite' => array( 'slug' => 'services', 'with_front' => false ),

		)
	);
}
add_action( 'init', 'create_my_post_types' );

// === CUSTOM TAXONOMIES === //
function my_custom_taxonomies() {
	register_taxonomy(
		'website_type',		// internal name = machine-readable taxonomy name
		'Services',		// object type = post, page, link, or custom post-type
		array(
			'hierarchical' => true,
			'label' => 'Website Types',	// the human-readable taxonomy name
			'query_var' => true,	// enable taxonomy-specific querying
			'rewrite' => array( 'slug' => 'website_type' ),	// pretty permalinks for your taxonomy?
		)
	);
	register_taxonomy(
		'service',
		'post',
		array(
			'hierarchical' => false,
			'label' => 'Service',
			'query_var' => true,
			'rewrite' => array( 'slug' => 'service' ),
		)
	);

}
add_action('init', 'my_custom_taxonomies', 0);

Please consult with your developer.

In wordpress add tags and categories to custom post type
In wordpress add tags and categories to custom post type

 

……………………..

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “In wordpress add tags and categories to custom post type”

Leave a Reply

Your email address will not be published.