Create and move terms for taxonomies

wp_update_term() doesn’t changes taxonomy. It just updated the existing taxonomy. Say the below code- $update = wp_update_term( 1, ‘category’, array( ‘name’ => ‘Uncategorized Renamed’, ‘slug’ => ‘uncategorized-renamed’ ) ); if ( ! is_wp_error( $update ) ) { echo ‘Success!’; } This code finds the category which ID is 1, then updates it to the name … Read more

Taxonomy query for children of parents

Use get_queried_object() to get the current queried term on a category page: $this_term = get_queried_object(); $args = array( ‘parent’ => $this_term->term_id, ‘orderby’ => ‘slug’, ‘hide_empty’ => false ); $child_terms = get_terms( $this_term->taxonomy, $args ); echo ‘<ul>’; foreach ($child_terms as $term) { echo ‘<li><h3><a href=”‘ . get_term_link( $term->name, $this_term->taxonomy ) . ‘”>’ . $term->name . ‘</h3></a></li>’; … Read more

Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy

Something like this should help: <?php $post_type=”animals”; $tax = ‘vertebrate’; $tax_terms = get_terms($tax); if ( $tax_terms ) { foreach ($tax_terms as $tax_term) { $args = array( ‘post_type’ => $post_type, “$tax” => $tax_term->slug, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘caller_get_posts’ => 1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ); // $my_query = null; <- REMOVE THIS, … Read more

get_terms return errors

As i was mentioning before, it’s a case of your term fetching occuring before the taxonomy has been registered. The init action occurs after the theme’s functions file has been included, so if you’re looking for terms directly in the functions file, you’re doing so before they’ve actually been registered. Here’s a portion of the … Read more

get taxonomy terms for parent and child

You should have two foreach loops. One for getting parent taxonomy terms, and second for getting child taxonomy terms. In the second foreach you need to specify the parent taxonomy term ID which is $parent_term->term_id from the first foreach loop. foreach( get_terms( ‘products-category’, array( ‘hide_empty’ => false, ‘parent’ => 0 ) ) as $parent_term ) … Read more