使用 WooCommerce 中的订单 ID 数组中的 WP_Query 过滤订单

Filter orders using a WP_Query from an array of orders IDs in WooCommerce

我得到了一组订单 ID,'post__in' => $orders_ids 将它们嵌入到 WP_Query 中:

$filters_orders = array(
    'post_status' => 'processing',
    'post_type' => 'shop_order',
    'posts_per_page' => 10,
    'post__in' => $orders_ids,
    'orderby' => 'modified',
    'order' => 'ASC'
);

$loop = new WP_Query($filters_orders);
while ($loop->have_posts()) {
    $loop->the_post();
    $order = new WC_Order($loop->post->ID);

    <HERE_MY_CUSTOM_HTML_TABLE>
}

我只过滤 "processing" 订单状态,但它不起作用,我得到了所有类型的状态。

我做错了什么? WP_Query?

如何正确过滤订单状态

WP_Query 中,您需要像在数据库 table wp_posts 中那样使用 post_status slug…所有订单状态都以“wc- 开头":

所以在你的情况下:'post_status' => 'wc-processing'.

现在应该可以了。