Loader That assists with registering taxonomy taxonomies to a WordPress website.
composer require underpin/taxonomy-loader
This plugin uses a built-in autoloader, so as long as it is required before Underpin, it should work as-expected.
require_once(__DIR__ . '/underpin-taxonomies/taxonomies.php');
- Install Underpin. See Underpin Docs
- Register new taxonomies menus as-needed.
A very basic example could look something like this.
// Register taxonomy
underpin()->taxonomies()->add( 'taxonomy', [
'post_type' => 'post', // Defaults to post.
'id' => 'ingredients', // Required. See register_taxonomy
'description' => 'Ingredients for this recipe', // Human-readable description.
'name' => 'Ingredients', // Human-readable name. Usually plural. Will set "label" argument if name is unset in args.
'args' => [ // Default atts. See register_taxonomy
'public' => true,
],
] );
Alternatively, you can extend Taxonomy
and reference the extended class directly, like so:
underpin()->taxonomies()->add('taxonomy-key','Namespace\To\Class');
A Taxonomy instance includes a method, called query
, which serves as a wrapper for new WP_Term_Query
.
This encapsulates queries for this taxonomy in a method, and gives you a place to override exactly how this taxonomy is queried, should you decide to extend the class.
underpin()->taxonomies()->get( 'taxonomy' )->query();
Like querying, Taxonomy instances includes a method called save
which serves as a wrapper for wp_insert_term
and wp_update_term
. It also includes notice-logging so you can track what happens on a request.
This encapsulates save actions for this taxonomy in a set of methods, and gives you a place to override exactly how this taxonomy is saved, should you decide to extend the class.
underpin()->taxonomies()->get( 'taxonomy' )->save( [/* see wp_insert_post */] );
This works in the same way as save
and query
. It includes logging, and provides a way to encapsulate the action.
underpin()->taxonomies()->get( 'taxonomy' )->delete( $term );