Woocommerce - 页面模板 - 按billing_first_name排序

时间:2016-10-28 10:41:06

标签: woocommerce orders

我制作了一个包含我的订单列表的模板,并希望按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 个答案:

答案 0 :(得分: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')类别?