Created
June 25, 2014 14:03
-
-
Save DWboutin/87ae62a907d30ec493f2 to your computer and use it in GitHub Desktop.
Woocommerce get product cat count
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function wp_get_productcat_postcount($id) { | |
//return $count; | |
$args = array( | |
'post_type' => 'product', //post type, I used 'product' | |
'post_status' => 'publish', // just tried to find all published post | |
'posts_per_page' => -1, //show all | |
'tax_query' => array( | |
'relation' => 'AND', | |
array( | |
'taxonomy' => 'product_cat', //taxonomy name here, I used 'product_cat' | |
'field' => 'id', | |
'terms' => array( $id ) | |
) | |
) | |
); | |
$query = new WP_Query( $args); | |
/* | |
echo '<pre>'; | |
print_r($query->post_count); | |
echo '</pre>'; | |
*/ | |
return (int)$query->post_count; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment