0

我正在寻找具有多个订单的 woocommrce 排序,例如“orderby _sales_price,_price”。

get_catalog_ordering_args( $orderby = '', $order = '' ) {
switch ( $orderby ) {
        default :
             //Defult PATCH;
            //$args['orderby']  = 'menu_order title';
                            $args['orderby']  = 'meta_value_num';
            #$args['order']    = $order == 'DESC' ? 'DESC' : 'ASC';
                            $args['order']    = 'DESC';
            #$args['meta_key'] = '';
                            $args['meta_key'] = '_sale_price';
                            #echo "<pre>";print_r($ordering);exit;
        break;
    }

}

这里唯一重要的是我改变了返回参数

$args['orderby']  = 'meta_value_num';
$args['order']    = 'DESC';
$args['meta_key'] = '_sale_price';

现在我的一级问题已解决,但我希望通过多个字段的订单在此处进行更多自定义,例如

$args['orderby']  = 'meta_value_num';
$args['order']    = 'DESC';
$args['meta_key'] = '_sale_price, _price';

让我知道是否需要任何信息并且没有得到相同的信息。

问候, 吉加尔

4

1 回答 1

0

在这里我找到了我的答案。

if($q['post_type']=="product") {

    if($orderby ==="ORDER BY $wpdb->postmeta.meta_value+0 DESC") {
         $orderby_c = "ORDER BY pm1.meta_value+0 DESC,pm2.meta_value+0 DESC";
    } else if($orderby==="ORDER BY $wpdb->postmeta.meta_value+0 ASC") {
         $orderby_c = "ORDER BY pm1.meta_value+0 ASC,pm2.meta_value+0 ASC";
    } else {
         $orderby_c = "ORDER BY pm1.meta_value+0 DESC,pm2.meta_value+0 DESC";
    }

    $this->request = "SELECT $found_rows $distinct $wpdb->posts.ID FROM $wpdb->posts
                                          LEFT JOIN $wpdb->postmeta pm1 ON $wpdb->posts.ID = pm1.post_id
                                          LEFT JOIN $wpdb->postmeta pm2 ON $wpdb->posts.ID = pm2.post_id
                                          WHERE $wpdb->posts.post_type = 'product' AND $wpdb->posts.post_status = 'publish' 
                                          AND pm1.meta_key = '_sale_price' 
                                          AND pm2.meta_key = '_price' 
                                          $orderby_c $limits";

}

于 2014-01-16T10:08:32.397 回答