What is the difference between a custom post type and a custom taxonomy?
| Point | Custom post type | Custom taxonomy |
|---|---|---|
| What | A new type of content | A new way to group content |
| Example | Book, Movie, Event | Genre, Brand, Location |
| Register with | register_post_type() | register_taxonomy() |
| Stored in | wp_posts (post_type) | wp_terms, wp_term_taxonomy and wp_term_relationships |
| Like | Posts and pages | Categories 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. |