php - 为什么我有 WooCommerce 订单,但没有 shop_order 类型的帖子?

标签 php wordpress woocommerce

我的店里有大约 30 个订单。我试图遍历所有订单,但我无法检索任何订单。这是代码:

$args = array (
            'post_type'         => 'shop_order',
            'posts_per_page'    => - 1
);

$loop = new WP_Query($args);

while ($loop->have_posts()) {
    // do some work here
}

循环永远不会运行。我尝试打印所有帖子类型的计数:

$args = array (
        'post_type'         => 'any',
        'posts_per_page'    => - 1
);

$loop = new WP_Query($args);    
$types = array();

while ($loop->have_posts()) {
    $loop->the_post();
    $post_id = get_the_ID();
    $type = get_post_type($post_id);
    if ($types[$type]) $types[$type]++;
    else $types[$type] = 1; 
}

foreach ($types as $type => $count) {
    echo "{$type}: {$count} ";
}

这是打印 product:30 page:5 post:1,即没有 shop_order。我想我遗漏了一些非常明显的东西,但对我来说,那个明显的东西是什么并不是那么明显!

更新:我现在正在使用此代码检索所有订单:

$args = array(
        'post_type'         => 'shop_order',
        'posts_per_page'    => -1
);

$posts = get_posts($args);

但这并没有回答问题。但这是一个解决方案。

最佳答案

使用 'post_status' => 'wc-processing''post_status' => 'any'

关于php - 为什么我有 WooCommerce 订单,但没有 shop_order 类型的帖子?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43106393/

相关文章:

javascript - 如何将特定插件加载到 WordPress 中的 ajax 处理程序?

nginx - Nginx 中的多站点 WordPress 重写规则

php - 使用 get_post_meta 数组作为 meta_query 值

php - 如何将wordpress与基于服务器的数据库连接

php - 如何设置状态

php - 根据发货国家/地区使 Woocommerce 结帐电话字段可选

php - Woocommerce 附加信息选项卡 : Adding product custom field value

javascript - 从 PHP 获取变量设置 Javascript 变量

php - 当我想使用 file_get_contents() 时超时

php - 拉维尔 : enabling debug toolbar