Woocommerce - 页面模板 - 按 billing_first_name 排序

Woocommerce - Page Template - Order by billing_first_name

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

我该如何解决这个问题?

谢谢

这将按 _billing_first_name 元字段对您的 post 进行排序:

$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') 类别设置为 post?