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

Sort posts by number of matched terms

Well the only way i can think of is to create an two dimentions array of the results you want to output, and the number of matching tags. so for example: $results = array(); $searched_tags = $_post[‘my_tax’]; $searched_tags = explode(“+”, $searched_tags); while (have_posts()){ $the_post(); $result[‘r’] = ‘<div class=”post”> <div class=”title”><h2><a href=”‘.get_permalink($post->ID).'” title=”‘.get_the_title($post->ID).'”>’.get_the_title($post->ID).'</a></h2></div> <div class=”excerpt”>’.get_the_excerpt().'</div> </div>’; … Read more

The same slug in multiple taxonomies

When you say keyword, do you mean term? I just did a quick test to confirm: I can have the same term, which has the same slug, in both the Category and Post Tag taxonomies, so I assume that custom taxonomies likewise can have terms with the same slug. So, might there be some taxonomy/term … Read more

Retrieving custom taxonomy in order, but excluding specific tax IDs

Alas no answers or comments! 😛 Not to worry, a colleague helped me out here and here is the above code working with an $exclude function terms_by_order($taxonomy, $exclude) { global $post; $terms = get_the_terms($post->ID, $taxonomy); // check input if ( empty($terms) || is_wp_error($terms) || !is_array($terms) ) return; // exclude foreach ($terms as $key=>$term) { if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)