Add missing JOIN parts from tax meta and meta queries.

The SQL query used to calculate the product counts using the product
attributes lookup table for the attribute filtering widget was missing
the JOIN parts coming from the tax meta and meta queries. The WHERE
parts however were being used, so the enitre query could fail if there
was a tax or meta query in place.
This commit is contained in:
Nestor Soriano 2021-07-12 10:23:59 +02:00
parent 70431ead2b
commit 4b4f9a2b5d
No known key found for this signature in database
GPG Key ID: 08110F3518C12CAD
1 changed files with 3 additions and 1 deletions

View File

@ -196,7 +196,9 @@ class Filterer {
$query['select'] = 'SELECT COUNT(DISTINCT product_or_parent_id) as term_count, term_id as term_count_id';
$query['from'] = "FROM {$this->lookup_table_name}";
$query['join'] = "INNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$this->lookup_table_name}.product_or_parent_id";
$query['join'] = "
{$tax_query_sql['join']} {$meta_query_sql['join']}
INNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$this->lookup_table_name}.product_or_parent_id";
$term_ids_sql = $this->get_term_ids_sql( $term_ids );
$query['where'] = "