This repository has been archived by the owner on Jun 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Adding a taxonomy
Koen edited this page Sep 12, 2019
·
6 revisions
Taxonomies are used to add categories or tags to post types. We're using TaxonomyAbstract
with sensible defaults, which is extended per taxonomy.
- Create a class in
Grrr\Taxonomies
, extendingTaxonomyAbstract
- Call the
register
function infunctions.php
An example for a taxonomy class could be:
namespace Grrr\Taxonomies;
class ExampleType extends TaxonomyAbstract {
protected $_taxonomy = 'example-type';
protected $_slug = 'type';
protected $_name = 'Example Types';
protected $_singular_name = 'Example Type';
protected $_args = [
'rewrite' => [
'slug' => '<post-type-slug>/type',
],
];
}
For all available arguments of the underlying register_taxonomy
used, view the WordPress codex or code reference.
There are two ways to bind a taxonomy to a post type:
- Specify the post type during taxonomy registration. It's the second parameter of the
register_taxonomy
method, and it can either be an array or a single post type. - Add it to the
taxonomies
array while registering the post type.
We're using the second method, since that show in the post type itself which taxonomies it's using.
- The registered name cannot be longer than 32 characters