What is the difference between a custom post type and a custom taxonomy?

PointCustom post typeCustom taxonomy
WhatA new type of contentA new way to group content
ExampleBook, Movie, EventGenre, Brand, Location
Register withregister_post_type()register_taxonomy()
Stored inwp_posts (post_type)wp_terms, wp_term_taxonomy and wp_term_relationships
LikePosts and pagesCategories and tags
<?php
add_action( 'init', function () {
	register_post_type( 'movie', array( 'label' => 'Movies', 'public' => true, 'show_in_rest' => true ) );
	register_taxonomy( 'genre', 'movie', array( 'label' => 'Genres', 'hierarchical' => true, 'show_in_rest' => true ) );
} );
Terminal output

$ wp post-type list –name=movie –fields=name,label,public
name label public
movie Movies 1
$ wp taxonomy list –object_type=movie –fields=name,label,hierarchical
name label hierarchical
genre Genres 1

The taxonomy is attached to the post type, so a movie can have a genre. Learn both: Custom Post Types and Custom Taxonomies.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.