Group by term ID to prevent duplicates

Fixes #14861
This commit is contained in:
Mike Jolley 2017-05-19 15:27:57 +01:00
parent 9f4b29a677
commit eae2fb64c8
1 changed files with 4 additions and 1 deletions

View File

@ -519,7 +519,7 @@ function wc_terms_clauses( $clauses, $taxonomies, $args ) {
}
// Query fields.
$clauses['fields'] = 'DISTINCT ' . $clauses['fields'] . ', tm.meta_value';
$clauses['fields'] = $clauses['fields'] . ', tm.meta_value';
// Query join.
if ( get_option( 'db_version' ) < 34370 ) {
@ -528,6 +528,9 @@ function wc_terms_clauses( $clauses, $taxonomies, $args ) {
$clauses['join'] .= " LEFT JOIN {$wpdb->termmeta} AS tm ON (t.term_id = tm.term_id AND tm.meta_key = '" . esc_sql( $meta_name ) . "') ";
}
// Grouping.
$clauses['where'] .= ' GROUP BY t.term_id ';
// Default to ASC.
if ( ! isset( $args['menu_order'] ) || ! in_array( strtoupper( $args['menu_order'] ), array( 'ASC', 'DESC' ) ) ) {
$args['menu_order'] = 'ASC';