itsmejgrant / taxonomy-helper
A tiny package to abstract away the pain of creating custom taxonomies in WordPress.
Installs: 270
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/itsmejgrant/taxonomy-helper
Requires
- php: >=7.4
README
A super simple abstraction to make creating a custom Taxonomies in WordPress a breeze.
Installation
You can either a) install with composer or b) copy the main the file and require it your functions file.
Composer
In your terminal, in the directory where your composer.json is (usually the theme directory):
composer require itsmejgrant/custom-taxonomy-helper
Then, in your function.php file:
use Itsmejgrant\TaxonomyHelper\Taxonomy
That's it, you're ready to go!
Manual installation
Copy the contents of the Taxonomy.php file and put it whereever makes sense in your theme directory.
Require it whereever you will be using it with:
require 'path/to/your/Taxonomy.php';
Usage
To use the helper, assign a new instance to a variable and manipulate as required. The only required arguments are the name of the taxonomy and either a string or array of post types to assign it to.
Examples:
function assigning_to_one_post_type() { $regions = new Taxonomy('Regions', 'posts'); } add_action('init', 'assigning_to_one_post_type');
function assigning_to_multiple_post_types() { $regions = new Taxonomy('Regions', ['posts', 'pages']); } add_action('init', 'assigning_to_multiple_post_types');