Woocommerce自定义代码按品牌和标题对产品进行排序

时间:2020-03-27 11:28:42

标签: sorting woocommerce title

我正在使用此代码按品牌和标题对产品进行排序,它可以工作,但同时管理控制台中的MEDIA未显示任何图像,请参阅此https://ibb.co/ct0zNcx

<pre>
add_filter('posts_clauses', 'posts_clauses_with_tax', 0, 500);
function posts_clauses_with_tax( $clauses, $wp_query ) {
global $wpdb;
$taxonomies = array('pwb-brand');
$orderBy['field'] = "pwb-brand";
$orderBy['direction'] = "ASC";
if( in_array($orderBy['field'], $taxonomies) ) {
$clauses['join'] .= "
    LEFT OUTER JOIN {$wpdb->term_relationships} AS rel2 ON {$wpdb->posts}.ID = rel2.object_id
    LEFT OUTER JOIN {$wpdb->term_taxonomy} AS tax2 ON rel2.term_taxonomy_id = tax2.term_taxonomy_id
    LEFT OUTER JOIN {$wpdb->terms} USING (term_id)";
$clauses['where'] .= " AND (taxonomy = '".$orderBy['field']."' OR taxonomy IS NULL)";
$clauses['groupby'] = "rel2.object_id";
$clauses['orderby']  = "GROUP_CONCAT({$wpdb->terms}.slug ORDER BY slug ASC) ";
//$clauses['orderby'] .= ( 'ASC' == strtoupper( $orderBy['direction'] ) ) ? 'ASC' : 'DESC';
//$clauses['orderby'] .= ", {$wpdb->posts}.post_title ASC";
return $clauses;
}
else {
return $clauses;
}
}
</pre>

0 个答案:

没有答案