You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$pieces['join'] .= " LEFT JOIN {$wpdb->termmeta} AS tm ON t.term_id = tm.term_id AND tm.meta_key = 'product_id'";
152
+
$meta_alias = 'tm_product_sort';
153
+
$product_alias = 'pt_product_sort';
154
+
$taxonomy_alias = 'ptt_product_sort';
155
+
156
+
// Join with termmeta to get product_id while avoiding alias collisions.
157
+
$pieces['join'] .= " LEFT JOIN {$wpdb->termmeta} AS {$meta_alias} ON t.term_id = {$meta_alias}.term_id AND {$meta_alias}.meta_key = 'product_id'";
149
158
150
159
// Join with terms and term_taxonomy to get wzkb_product name.
151
-
$pieces['join'] .= " LEFT JOIN {$wpdb->terms} AS pt ON tm.meta_value = pt.term_id";
152
-
$pieces['join'] .= " LEFT JOIN {$wpdb->term_taxonomy} AS ptt ON pt.term_id = ptt.term_id AND ptt.taxonomy = 'wzkb_product'";
160
+
$pieces['join'] .= " LEFT JOIN {$wpdb->terms} AS {$product_alias} ON {$meta_alias}.meta_value = {$product_alias}.term_id";
161
+
$pieces['join'] .= " LEFT JOIN {$wpdb->term_taxonomy} AS {$taxonomy_alias} ON {$product_alias}.term_id = {$taxonomy_alias}.term_id AND {$taxonomy_alias}.taxonomy = 'wzkb_product'";
153
162
154
163
// Set the ORDER BY clause with the "ORDER BY" prefix.
155
-
$pieces['orderby'] = "ORDER BY COALESCE(pt.name, '') $order, t.name $order";
164
+
$pieces['orderby'] = "ORDER BY COALESCE({$product_alias}.name, '') $order, t.name $order";
156
165
157
166
// Prevent WordPress from appending the order.
158
167
$pieces['order'] = '';
159
168
160
169
return$pieces;
161
170
}
162
171
172
+
/**
173
+
* Ensure Sections screen defaults to sorting by Product.
174
+
*
175
+
* @since 3.0.0
176
+
*
177
+
* @param \WP_Term_Query $query Term query instance.
0 commit comments