Skip to content

Instantly share code, notes, and snippets.

@DWboutin
Created June 25, 2014 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DWboutin/87ae62a907d30ec493f2 to your computer and use it in GitHub Desktop.
Save DWboutin/87ae62a907d30ec493f2 to your computer and use it in GitHub Desktop.
Woocommerce get product cat count
<?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