Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
register_taxonomy(
'acme-category',
$postType,
[
'label' => 'Acme Categories',
'rewrite' => ['slug' => 'acme-category'],
'capabilities' => [
'manage_terms' => 'manage_options',
'edit_terms' => 'manage_options',
'delete_terms' => 'manage_options',
'assign_terms' => 'manage_options',
],
'hierarchical' => true,
]
);
<?php
$termInfo = wp_insert_term(
$customPost->getName(),
'acme-category',
['slug' => sanitize_title_with_dashes($customPost->getName())]
);
<?php
$parentTermInfo = get_term_by(
'term_taxonomy_id',
$termInfo['term_taxonomy_id'],
'acme-category',
ARRAY_A
);
<?php
wp_set_object_terms(
$customPost->getId(),
[
$parentTermInfo['parent'],
$termInfo['term_id'],
],
'acme-category',
true
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment