使用 WP_Query 从 WooCommerce 中的订单 ID 数组中过滤订单 [英] Filter orders using a WP_Query from an array of orders IDs in WooCommerce
问题描述
我得到了一系列订单 ID 和 'post__in' =>$orders_ids
将它们嵌入到 WP_Query
中:
I got an array of orders ID's and 'post__in' => $orders_ids
to embed them in a 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>
}
我只过滤正在处理"的订单状态,但它不起作用,我得到了各种状态.
I am filtering "processing" order status only, but it doesn't work and I get all kind of status.
我做错了什么?如何在此 WP_Query 中正确过滤订单状态?
What I am doing wrong? How to filter order status correctly in this WP_Query?
推荐答案
在 WP_Query
中,您需要使用 post_status
slugs,就像在数据库表中一样 wp_posts
... 所有订单状态以wc-
"开头:
In a WP_Query
, you need to use the post_status
slugs like in the database table wp_posts
… All orders status start with "wc-
":
所以在你的情况下:'post_status' =>'wc-processing'
.
So in your case: 'post_status' => 'wc-processing'
.
现在应该可以了.
这篇关于使用 WP_Query 从 WooCommerce 中的订单 ID 数组中过滤订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!