Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Created February 14, 2019 15:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommcfarlin/a1d3464ee4f84864a002f5568586795f to your computer and use it in GitHub Desktop.
Save tommcfarlin/a1d3464ee4f84864a002f5568586795f to your computer and use it in GitHub Desktop.
<?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