Get Objects While Deleting term

Use the pre_delete_term hook, which fires before the actual deleting occurs, so the relationships will still be present. function wpse_296972_pre_delete_term( $term_id, $taxonomy_name ) { if ( $taxonomy_name === ‘organization’ ) { $objects = get_objects_in_term( $term_id, $taxonomy ); // Do something with $objects. } } add_action( ‘pre_delete_term’, ‘wpse_296972_pre_delete_term’ );

Pass array of taxonomy terms to wp_query

The problem is ambiguity, you can’t just put in ‘relation’ => ‘OR’ in the main parameter list, because how would WP_Query know if it’s for the tax_query and not the meta_query? For how it’s supposed to work, and where the relation parameter goes we need to refer to the official docs for WP_Query which gives … Read more

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