Get Current Custom Taxonomy ID by Post ID

(Probably better to use get_the_terms). $terms = wp_get_object_terms( $pid, ‘custom_category’, array(‘fields’=>’ids’)); Get an array of term ids (will always been array, even if it is an array of one): $ids = wp_list_pluck( $terms, ‘term_id’ ); If you just want one id… then ‘pop’ out the last id: $id = array_pop($ids); See also PHP docs on … Read more

get_term_children doesn’t return an array of children terms

At first, try passing the Taxonomy as a string: $children = get_term_children($term->term_id, ‘locations’); The function get_category_children produces a string as return, so you can just echo it. the function get_term_children, however, returns an array. To see the contents of the array, try print_r( $children ); instead of echo. The last thing to keep in mind … Read more

Do I have to set parent when set post term?

When you create a term for a hierarchical taxonomy, if you don’t specify a parent, its parent ID is set to 0. In other words, it becomes a parent term. Edited with regards to comments: Add specifically each term you wish to add to the post (parent terms aren’t automatically added if their children are). … Read more

List custom taxonomy terms from custom field

The problem you are facing is that get_the_terms() returns an array (or false or a WP_Error-Object), not a string. So, assuming that you have multiple terms for images, you could use a code like this: if( $labels && !is_wp_error( $labels ) ) { foreach( $labels as $label ) { $labelarray[] = $label->name; } $labelstring = … Read more

get_the_terms return only last term

Instead of get_the_terms try using get_terms and set the hierarchal argument to true. Also make sure you show empty so you are not hiding your empty categories. Try something like this: $args = array( ‘hide_empty’ => false, ‘hierarchical’ => true ); $terms = get_terms(‘portfolio_pt’, $args); foreach($terms as $term) echo $term->name;