Fix term counts when terms span taxonomies Closes #4738

This commit is contained in:
Mike Jolley 2014-02-13 14:51:43 +00:00 committed by Coen Jacobs
parent 9e4d10f269
commit 14944c849e
1 changed files with 5 additions and 2 deletions

View File

@ -411,7 +411,10 @@ function _wc_term_recount( $terms, $taxonomy, $callback = true, $terms_are_term_
$count_query = " $count_query = "
SELECT COUNT( DISTINCT posts.ID ) FROM {$wpdb->posts} as posts SELECT COUNT( DISTINCT posts.ID ) FROM {$wpdb->posts} as posts
LEFT JOIN {$wpdb->postmeta} AS meta_visibility ON posts.ID = meta_visibility.post_id LEFT JOIN {$wpdb->postmeta} AS meta_visibility ON posts.ID = meta_visibility.post_id
LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID = rel.object_ID LEFT JOIN {$wpdb->term_relationships} AS rel ON posts.ID=rel.object_ID
LEFT JOIN {$wpdb->term_taxonomy} AS tax USING( term_taxonomy_id )
LEFT JOIN {$wpdb->terms} AS term USING( term_id )
LEFT JOIN {$wpdb->postmeta} AS postmeta ON posts.ID = postmeta.post_id
$stock_join $stock_join
WHERE post_status = 'publish' WHERE post_status = 'publish'
AND post_type = 'product' AND post_type = 'product'
@ -448,7 +451,7 @@ function _wc_term_recount( $terms, $taxonomy, $callback = true, $terms_are_term_
} }
// Generate term query // Generate term query
$term_query = 'AND term_taxonomy_id IN ( ' . implode( ',', $terms_to_count ) . ' )'; $term_query = 'AND term_id IN ( ' . implode( ',', $terms_to_count ) . ' )';
// Get the count // Get the count
$count = $wpdb->get_var( $count_query . $term_query ); $count = $wpdb->get_var( $count_query . $term_query );