Filter orders using a WP_Query from an array of or

2019-07-23 19:27发布

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条回答
成全新的幸福
2楼-- · 2019-07-23 20:01

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.

查看更多
登录 后发表回答