Custom Taxonomy: Parent still counting deleted Child

The problem There’s on (imho) serious issue with WordPress and Taxonomies and their term hierarchy (and children): They aren’t really fetched from the actual state, but someone who thought (s)he might be really “smart” stuffed that into the *_options table. Just take a look at the source of get_term_children(): It makes a call to _get_term_hierarchy(). … Read more

WooCommerce – Display product child categories from specific parent

The woocommerce function get_categories() is declared in abstract-wc-product.php, because it is based on the wordpress function get_the_term_list() there is no way to get only a specific branch of a category. This absolutely isn’t the same as the wordpress function get_categories(), you can see that it is woocommerce specific by how it’s used $product->get_categories(). Besides the … Read more

get_children – wp_get_attachment_image

You could Limit the output to 1 like this but this is not a solution, only a workaround: $args = array(‘post_parent’ => get_the_ID(), ‘numberposts’ => 1, ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’ ); $images = get_children( $args ); if ($images) { foreach ($images as $image) { echo wp_get_attachment_image($image->ID, ‘full’); } } Have … Read more

How can I calculate the total number of categories at different hierarchy levels?

This is a bit broad to give you the full code, so ‘I’ll give you an outline. The idea is to loop through all categories and count how many parents each category has using get_term_parents_list (please look carefully what this function returns). This will tell you how deep the level of this category is. Then … Read more

How to order get_term_children output by alphabetic order

Per your comment (and hopefully an edit to the question) : I did it like so: foreach ( $termchildren as $child ) { $term = get_term_by( ‘id’, $child, $taxonomy_name, array( ‘orderby’ => ‘name’, ‘hide_empty’ => 0) ); Formatted: foreach ( $termchildren as $child ) { $term = get_term_by( ‘id’, $child, $taxonomy_name, array( ‘orderby’ => ‘name’, … Read more

Child terms from multiple parents?

We can filter the generated SQL query through the terms_clauses filter before the SQL query is executed. What we will be doing is to introduce a new parameter called wpse_parents which will accept an array of parent term ID’s to get children from. Note, this new parameter works exactly the same as the build-in parameter, … Read more

get_term_children for immediate children only (not grandchildren)

Use the get_terms() function instead: $term_children = get_terms( ‘mytaxname’, array( ‘parent’ => get_queried_object_id(), ) ); if ( ! is_wp_error( $terms ) ) { foreach ( $term_children as $child ) { echo ‘ <div class=”product-archive”> <div class=”post-title”> <h3 class=”product-name”><a href=”‘ . get_term_link( $child ) . ‘”>’ . $child->name . ‘</a></h3> </div> </div> ‘; } } get_terms() … Read more