First, you need to use Bazooka in Theme or in Plugin.
Register a Taxonomy
No matter how you organize your-folder/
source folder. You have to create a new class that implements TaxonomyInterface
like this :
use Fantassin\Core\WordPress\Taxonomy\Contracts\TaxonomyInterface;
class YourTaxonomy implements TaxonomyInterface
{
public function getKey(): ?string
{
return 'your-taxonomy';
}
public function getPostTypes(): ?string
{
return ['your-post-type'];
}
public function getArgs(): array
{
$labels = array(…);
return [
'labels' => $labels,
'public' => true,
'hierarchical' => false,
'has_archive' => true,
];
}
}
getKey()
method must return de Taxonomy key its corresponds to $taxonomy
parameters in official documentation : https://developer.wordpress.org/reference/functions/register_taxonomy/
getPostTypes()
method must return an array of Post Types key you want to link your taxonomy.
getArgs()
method must return an array of the same parameters as $args
in official documentation.
Even if getArgs
return empty array, we convert your Taxonomy key to Camel Case to get Singular Name and Plural Name.
That’s all… YourTaxonomy
is automatically register by Bazooka in ThemeKernel
or PluginKernel
.
We advise you to use Plugin to register custom Taxonomies instead of Theme. By using plugin, tomorrow, if your theme is inactive, you keep your features developed around your Taxonomies.