2016-10-28 93 views
1

我制作了一份带有我的订单列表的模板,并想按billing_first_name进行排序。我已经尝试了排列但没有成功:Woocommerce - 页面模板 - 通过billing_first_name排序

<?php 

global $woocommerce; 

$args = array(
    'post_type' => 'shop_order', 
    'post_status' => 'publish', 
      'posts_per_page' => -1, 
    'tax_query' => array(
       array(
        'taxonomy' => 'shop_order_status', 
        'field' => 'slug', 
        'terms' => array('processing', 'on-hold', 'pending', 'completed', 'cancelled', 'refunded', 'failed') 
       ) 
      ) 
); 


$loop = new WP_Query($args); 
?> 
    <article id="tabela_inscricoes"> 
    <div id="title_lista_inscritos">Order list</div> 
     <table cellspacing="0" cellpadding="2"> 
      <tbody> 
<?php 
while ($loop->have_posts()) : $loop->the_post(); 

    $order_id = $loop->post->ID; 
    $order = new WC_Order($order_id); 

?> 

       <tr> 
        <td style="text-align:left;"><?php echo $order->billing_first_name; ?> <?php echo $order->billing_last_name; ?></td> 
        <td style="text-align:left;"><?php echo $order->billing_company; ?></td> 
        <td style="text-align:left;"><?php echo custom_status($order); ?></td> 
       </tr> 


      </tbody>     
     </table>    
    </article> 

我该如何解决这个问题?

感谢

回答

1

这将责令你的帖子_billing_first_name元场:

$args = array(
    'post_type'  => 'shop_order', 
    'post_status' => 'publish', 
    'posts_per_page' => -1, 
    'meta_key'  => '_billing_first_name', 
    'orderby'  => 'meta_value', 
    'order'   => 'ASC' // or DESC 
); 


$loop = new WP_Query($args); 

此外,tax_query部分是多余的,除非你没有设置array('processing', 'on-hold', 'pending', 'completed', 'cancelled', 'refunded', 'failed')类别发布?