【问题标题】:Filter orders using a WP_Query from an array of orders IDs in WooCommerce使用 WP_Query 从 WooCommerce 中的订单 ID 数组中过滤订单
【发布时间】:2018-05-04 03:42:11
【问题描述】:

我有一组订单 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>
}

我只过滤“处理”订单状态,但它不起作用,我得到了各种状态。

我做错了什么?如何在这个 WP_Query 中正确过滤订单状态?

【问题讨论】:

    标签: php sql wordpress woocommerce orders


    【解决方案1】:

    WP_Query中,您需要使用post_status slug,就像在数据库表wp_posts中一样...所有订单状态都以“wc-”开头:

    所以在你的情况下:'post_status' =&gt; 'wc-processing'

    现在应该可以了。

    【讨论】:

    • 哦该死的..我检查了很多次代码..好的,谢谢@LoicTheAztec!
    猜你喜欢
    • 2017-07-08
    • 2020-05-08
    • 2021-07-14
    • 1970-01-01
    • 2019-09-08
    • 2017-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多