Display tags belonging to a specific post type only

I’ve been successfully using the following code from @StephenHarris from this answer. I have made a small tweak or two to the original code, but the most significant is to name the new count object to count_type from the original COUNT* that was returned by default Just in short again, the function works exactly like … Read more

Term begins with a letter

You will need to filter the query, which you can do with the terms_clauses hook. This is very similar to G-M’s solution but does not require a prefix on your search string. function old_style_name_like_wpse_123298($clauses) { remove_filter(‘term_clauses’,’old_style_name_like_wpse_123298′); $pattern = ‘|(name LIKE )\’%(.+%)\’|’; $clauses[‘where’] = preg_replace($pattern,’$1 \’$2\”,$clauses[‘where’]); return $clauses; } add_filter(‘terms_clauses’,’old_style_name_like_wpse_123298′); // $letter=”str”; // test $terms = … Read more

How to update incorrect post count in taxonomy?

It only took 3.5-years for someone to be put into the position of @robert-andrews to chase down the post count problem. While having the same problem (and misinterpretation), I ran across your post yesterday in my search for answers. Nothing good really turned up. So, I was forced to trace the code and take the … Read more

Get current term’s ID

Here is a function I use to list subterms: /** * Lists all subentries of a taxonomy. * * @return void */ function ttt_get_subterms( $args = array () ) { if ( ! isset ( get_queried_object()->taxonomy ) ) { return; } $options = array ( ‘child_of’ => get_queried_object_id() , ‘echo’ => 0 , ‘taxonomy’ => … Read more

Get main parent categories for a product

just to offer a alternative solution that might help somebody: code function wc_origin_trail_ancestor( $link = false, $trail = false ) { if (is_product_category()) { global $wp_query; $q_obj = $wp_query->get_queried_object(); $cat_id = $q_obj->term_id; $descendant = get_term_by(“id”, $cat_id, “product_cat”); $descendant_id = $descendant->term_id; $ancestors = get_ancestors($cat_id, ‘product_cat’); $ancestors = array_reverse($ancestors); $origin_ancestor = get_term_by(“id”, $ancestors[0], “product_cat”); $origin_ancestor_id = $origin_ancestor->term_id; … Read more

wp_get_object_terms – How can I order the resulting array by hierarchy?

Just a rough sketch to get your idea: countries (hierarchical taxonomy) France (country – sub taxonomy) Champagne (state – sub sub taxonomy) Le Mans (city – term) Angers (city – term) Nantes (city – term) And you want to order: $query_results = query( ‘country’ => ‘france’, ‘orderby’ => ‘state city’, ‘order’ => ‘ASC’ ); Did … Read more