PostTypes
  • PostTypes v2.2.1
  • Getting Started
  • PostTypes
    • Create a Post Type
    • Add Taxonomies
    • Filters
    • Columns
    • Menu Icons
    • Flush Rewrite Rules
  • Taxonomies
    • Create a Taxonomy
    • Add to Post Type
    • Columns
  • Notes
  • Contributing
  • Changelog
Powered by GitBook
On this page
  1. PostTypes

Add Taxonomies

PreviousCreate a Post TypeNextFilters

Last updated 6 years ago

You can add new and existing taxonomies to a post type by passing the taxonomy name to the taxonomy() method.

// Create a book post type.
$books = new PostType( 'book' );

// Add the genre taxonomy to the book post type.
$books->taxonomy( 'genre' );

// Add the default category taxonomy.
$books->taxonomy( 'category' );

// Register the post type to WordPress.
$books->register();

This method only attaches the taxonomy to the post type, to create a taxonomy see the on creating a new taxonomy.

Taxonomies and post types can be created in any order.

documentation