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

主宰稳场 提交于 2019-12-24 16:37:15

问题


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.

What I am doing wrong? How to filter order status correctly in this WP_Query?


回答1:


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-":

So in your case: 'post_status' => 'wc-processing'.

This should work now.



来源:https://stackoverflow.com/questions/47400181/filter-orders-using-a-wp-query-from-an-array-of-orders-ids-in-woocommerce

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!