Articles of get terms

Custom Taxonomy Archive BUG

I’m hoping that Its just my tired eyes missing something and a fresh pair of eyeballs might catch what I’m missing. I have a custom taxonomy with a slug of ‘residential_project_types’ that is assigned to a custom post type of residential_projects. I want to display all terms from the taxonomy, outputting the term name and […]

Get Current Custom Taxonomy ID by Post ID

If I know the current post id that i have in the variable $pid I use $terms = get_the_terms($pid, ‘custom_category’); How do I get just the term id/term_taxonomy_id if I var_dump $terms I see what I want…but I have no idea how the heck to return just the id, not an array, just the id. […]

Have a Custom Post Type index page display taxonomy items instead of posts

I have a CPT registered that is called lessons with a custom taxonomy (category) that is called courses. I want the /courses page (archive-courses.php?) to display the individual courses (i.e. “online marketing”, “paid advertising”) and not the individual posts (lessons). Would this mean I’d just customize the loop, or a complete custom WP_Query?

How to output wordpress custom tags separated by comma?

Based on a few references I’ve built a function to output a list of custom taxonomy terms separated by comma. The code works as intended, where food_tag is the custom taxonomy I registered for a custom post_type. Here’s the function: function get_taxonomy_food_tags(){ $terms = get_terms(‘food_tag’); foreach($terms as $term){ // The $term is an object, so […]

List only first-level children of specific custom taxonomy term

I have a site set up with the following: Post Type: product Taxonomy: product_cat Taxonomy Slug: hydro The term hydro has several immediate child terms and several grandchild terms. I need to write a loop that will display only the first-level children of the custom taxonomy term “hydro” (i.e – skip grandchild terms), along with […]

Get direct children of custom taxonomy

I’ve googled extensively and tried my best, but I just can’t get the first level children of the custom taxonomy in the code below to work! It only displays the parent level. What I am trying to achieve is the following: Level 1 <— at the moment, it only displays this level Level 2 <– […]

Add current class to queried term on taxonomy term archive

I’m currently using get_terms to list terms of a certain taxonomy. I would like to add a class to the term currently being queried via the archive template. I tried putting together the below code but this bizarrely results in the class being applied to not just the current term being queried but every term […]

Get terms from multiple taxonomies

I have to get all the terms from four taxonomies: vehicle_safely_features vehicle_exterior_features vehicle_interior_features vehicle_extras I tried this: $terms = get_terms( array( ‘taxonomy’ => ‘vehicle_safely_features’, ‘vehicle_exterior_features’, ‘vehicle_interior_features’, ‘vehicle_extras’ ) ); But, it only gets terms of vehicle_safely_features and not all of the taxonomies.

How to get the top most term (top ancestor) of a custom taxonomy child term?

I need to get the topmost term (top level ancestor) of a taxonomy term. Suppose the following term hierarchy: North America United States New York New York City South America Mexico I need to get the ID of “North America” term if I know the ID of “New York” I’m using an adapted function found […]

get_terms() doesn't return empty terms even though hide_empty is false

I can’t manage to make get_terms() to return the empty terms and I’ve tried it in a number of ways. Here’s the code: $terms = get_terms(‘device’,array(‘hide_empty’ => 0)); foreach($terms as $term) { if($term->parent == 0) { if($i++ != 0) echo ‘</optgroup>’; echo ‘<optgroup label=”‘.$term->name.'”>’; $id = $term->term_id; $args = array(“child_of”=>$id); $this_term = get_terms(‘device’,$args); foreach($this_term as […]