I have a custom taxonomy called Resources
. Within resources, I have defined a category called "type". This is its structure:
Type
- Blog
- Case study
- Webinar
So category "type" has three sub categories.
I'm trying to get (and display) the subcategories from the parent. But the array
is showing up empty?
Type
has the ID of 32.
Approach:
$type_id = 32;
$taxonomies = array(
'category',
);
$args = array(
'parent' => $type_id,
// 'child_of' => $type_id,
);
$terms = get_terms($taxonomies, $args);
var_dump($terms);
returns array(0) { }
Edit:
How I've defined the taxonomy:
register_post_type(
'resources',
tp_build_post_args(
'resources', 'Resource', 'Resources',
array(
'menu_icon' => 'dashicons-welcome-write-blog',
'menu_position' => 20,
'has_archive' => true,
'public' => true,
'supports' => array('editor', 'title','author','thumbnail', 'revisions'),
'taxonomies' => array('resource', 'category')
)
)
);
And also tried:
$type_id = 32;
$taxonomies = array(
'resource',
);
$args = array(
'parent' => $type_id,
// 'child_of' => $type_id,
);
$terms = get_terms($taxonomies, $args);
var_dump($terms)
now returns object(WP_Error)#5443 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(17) "Invalid taxonomy." } } ["error_data"]=> array(0) { } }