get_terms() for custom taxonomy related to another taxonomy

You can try getting all the posts IDs from the first taxonomy $objects = get_posts( array( ‘category’ => ‘history’, ‘numberposts’ => -1, ) ); foreach ($objects as $object) { $objects_ids[] = $object->ID; } Then get the terms from the second taxonomy associated with them: $collections = wp_get_object_terms( $object_ids, ‘collections’ );

Display post taxonomies tree

What about: $taxName = “tvr_amenity”; $terms = get_terms($taxName,array(‘parent’ => 0)); foreach($terms as $term) { echo ‘<a href=”‘.get_term_link($term->slug,$taxName).'”>’.$term->name.'</a>’; $term_children = get_term_children($term->term_id,$taxName); echo ‘<ul>’; foreach($term_children as $term_child_id) { $term_child = get_term_by(‘id’,$term_child_id,$taxName); echo ‘<li><a href=”‘ . get_term_link( $term_child->name, $taxName ) . ‘”>’ . $term_child->name . ‘</a></li>’; } echo ‘</ul>’; }

Difference between get_category, get_term_by and get_categories

To fully understand the difference between get_categories(), get_category() and get_term_by(), you need to have a look at how these functions are constructed. get_categories($args) as its name suggest, get a list of all categories created on the site. This function can be found in “wp-includes/category.php” lines 39 to 66 39 function get_categories( $args = ” ) { 40        $defaults = array( ‘taxonomy’ => ‘category’ ); … Read more

How to order a list of taxonomy terms alphabetically?

I found an answer to this at https://wordpress.stackexchange.com/a/105079/40536 I modified my code to the following: <form action=”<?php bloginfo(‘url’); ?>/” method=”get”> <?php $term_id = 279; $taxonomy_name=”categories”; $termchildren = get_term_children( $term_id, $taxonomy_name ); $children = array(); foreach ($termchildren as $child) { $term = get_term_by( ‘id’, $child, $taxonomy_name ); $children[$term->name] = $term; } ksort($children); echo ‘<select name=”‘ . … Read more

Empty tax_query array returns an empty array

As already hinted by @Milo, check if you have terms before appending your tax_query You can try the following: (Requires PHP 5.4+ due to short array syntax, revert to old syntax if necessary) $args = [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 15, ‘paged’ => $paged, ‘post__not_in’ => $exclude, ‘s’ => $filter, ]; // Append our … Read more

How do I get the current tag out of a taxonomy?

What you are looking for is get_the_terms(). You can get custom terms for the current post by using the following code: $post_tags = get_the_terms(get_the_ID(), ‘portfolio_tags_client’); if ($post_tags) { ?> <div class=”tags-div”> <h3><?php _e( ‘Tags’, ‘text-domain’ ); ?></h3> <div class=”post-tags”><?php foreach($post_tags as $tag) { echo ‘<a href=”‘.get_tag_link($tag->term_id).'” title=”‘.$tag->name.'”>’. $tag->name .'</a>’; } ?> </div> </div><?php } This … Read more