Created
July 2, 2014 14:26
-
-
Save DWboutin/dec8876b7ee65676ee56 to your computer and use it in GitHub Desktop.
Custom taxonomy post 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 catCount($slug){ | |
| global $wpdb; | |
| $query = " | |
| SELECT COUNT( DISTINCT cat_posts.ID ) AS post_count | |
| FROM gh_term_taxonomy AS cat_term_taxonomy INNER JOIN gh_terms AS cat_terms ON | |
| cat_term_taxonomy.term_id = cat_terms.term_id | |
| INNER JOIN gh_term_relationships AS cat_term_relationships | |
| ON cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id | |
| INNER JOIN gh_posts AS cat_posts | |
| ON cat_term_relationships.object_id = cat_posts.ID | |
| WHERE cat_posts.post_status = 'publish' | |
| AND cat_posts.post_type = 'product' | |
| AND cat_term_taxonomy.taxonomy = 'product_cat' | |
| AND cat_terms.slug = ('$slug') | |
| "; | |
| return $wpdb->get_var($query); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment