Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Could anyone help me to implement this code in WooCommerce, ie instead of categories to use product categories, and instead of tag to use product tag.

In functions.php :

function get_category_tags($args) {
global $wpdb;
$tags = $wpdb->get_results
("
    SELECT DISTINCT terms2.term_id as tag_id, terms2.name as tag_name, null as tag_link
    FROM
        wp_posts as p1
        LEFT JOIN wp_term_relationships as r1 ON p1.ID = r1.object_ID
        LEFT JOIN wp_term_taxonomy as t1 ON r1.term_taxonomy_id = t1.term_taxonomy_id
        LEFT JOIN wp_terms as terms1 ON t1.term_id = terms1.term_id,

        wp_posts as p2
        LEFT JOIN wp_term_relationships as r2 ON p2.ID = r2.object_ID
        LEFT JOIN wp_term_taxonomy as t2 ON r2.term_taxonomy_id = t2.term_taxonomy_id
        LEFT JOIN wp_terms as terms2 ON t2.term_id = terms2.term_id
    WHERE
        t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
        t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'
        AND p1.ID = p2.ID
    ORDER by tag_name
");
$count = 0;
foreach ($tags as $tag) {
    $tags[$count]->tag_link = get_tag_link($tag->tag_id);
    $count++;
}
return $tags;
}

In wp theme:

$args = array('categories'=> '3'); 
$tags = get_category_tags($args); 
$content .= "<ul>"; 
foreach ($tags as $tag) { 
    $content .= "<li><a href=\"$tag->tag_link\">$tag->tag_name</a></li>";
} 
$content .= "</ul>"; 
echo $content; 
share|improve this question
add comment

1 Answer 1

Finally solve the problem:

t1.taxonomy = 'product_cat' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND
t2.taxonomy = 'product_tag' AND p2.post_status = 'publish'

In the functions.php

t1.taxonomy = 'category' AND p1.post_status = 'publish' AND terms1.term_id IN (".$args['categories'].") AND t2.taxonomy = 'post_tag' AND p2.post_status = 'publish'

rename category to product_cat, and post_tag with product_tag.

share|improve this answer
    
Can you post a bit more of the code or set up the code that solved your problem. I think this will be more helpful to other users. –  BandonRandon Nov 1 '12 at 17:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.