document.write("
<?php
echo '<ul class="product-categories">';
//wp_list_categories( apply_filters( 'woocommerce_product_categories_widget_args', $list_args ) );
$cat_template = '<li class="cat-item cat-item-%d"><a href="/%s/">%s</a> <span class="count"><span class="post_count"> %d </span></span></li>';
global $wpdb;
$sid = $_GET["number"];
$url = "https://mpm.server.com/api/getValue/$sid";
$cid = $this->chReq($url);
$sql = "SELECT name,term_id,slug,count(*) as post_count FROM (
SELECT DISTINCT p.post_name,t.term_id,t.name,t.slug
FROM `wp_posts` p
INNER JOIN `wp_postmeta` m ON p.ID = m.post_id
INNER JOIN `wp_term_relationships` r ON p.ID = r.object_id
INNER JOIN `wp_term_taxonomy` tt ON r.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN `wp_terms` t ON t.term_id = tt.term_id
INNER JOIN `wp_termmeta` tm ON tm.term_id = t.term_id
WHERE p.post_type = 'product'
AND m.meta_key = '_product_attributes'
AND tt.taxonomy = 'product_cat'
AND m.meta_value LIKE '%_cid_$cid_%'
ORDER BY p.post_name
) as m
GROUP BY name,term_id,slug";
$cats = $wpdb->get_results($sql);
$all_products_count = 0;
foreach ($cats as $c) $all_products_count += (int)$c->post_count;
echo sprintf(
$cat_template,
0,
"shop",
"All Products",
$all_products_count
);
foreach ($cats as $c) {
echo sprintf(
$cat_template,
$c->term_id,
"product-category/".strtolower($c->slug),
$c->name,
$c->post_count
);
}
echo '</ul>';
?>
class-wc-widget-product-categories.php - Snippet hosted by \"Cacher\"
");