Custom taxonomy
The Custom_Taxonomy
class is likely designed to register a custom taxonomy in WordPress. A taxonomy in WordPress is used to group content, like categories or tags. Custom taxonomies are helpful when you want to create custom classification structures for specific post types.
This class simplifies the process of registering a custom taxonomy by allowing you to pass key parameters when you instantiate it. These parameters help define the taxonomy’s behavior, including its name, associated post types, and how it should appear on the website.
Parameters:
Section titled “Parameters:”-
taxonomy: This defines the machine-readable name (or slug) for the taxonomy. Example: ‘media-and-press-category’ is the name of the taxonomy and will be used internally by WordPress to identify it.
-
object_type: This specifies the post types that will use this taxonomy. Example: array(‘media-and-press’) means this taxonomy will be associated with the custom post type media-and-press, so posts under this type can be categorized with this taxonomy.
-
singular_name: This is the human-readable, singular name of the taxonomy, which will be used in the WordPress admin and user interface. Example: ‘Category’ is the name that will appear when referring to a single category in the admin.
-
plural_name: This defines the plural version of the taxonomy’s name, which is also displayed in the WordPress admin. Example: ‘Media and Press Categories’ will be used in areas like taxonomy lists or selection options for grouping multiple categories.
-
args: This is an object that contains the additional arguments or options for registering the taxonomy. These options allow for further customization of how the taxonomy behaves and appears.
-
rewrite: This defines how the taxonomy’s URLs should be structured.
You can find the full class implementation here.
Example Usage
Section titled “Example Usage”<?php new Custom_Taxonomy((object) array( 'taxonomy' => 'media-and-press-category', 'object_type' => array('media-and-press'), 'singular_name' => 'Category', 'plural_name' => 'Media and Press Categories', 'args' => (object) array( 'rewrite' => array('slug' => 'media-and-press-category', 'with_front' => false) ) ));?>