2
私の店では30件も注文しています。私はすべての注文をループしようとしていますが、注文は取得できません。コードは次のとおりです。WooCommerceの注文はありますが、shop_orderタイプの投稿はありません。なぜですか?
$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
Sを印刷しています。私は何か非常に明白なものを見逃していると思うが、それは明白なことではない。
UPDATE:私は今、このコードですべての注文を取得しています:
$args = array(
'post_type' => 'shop_order',
'posts_per_page' => -1
);
$posts = get_posts($args);
しかし、質問に答えていません。しかしそれは解決策です。
はまったく同じことが今の私に起こっています。新しいオカレンスのみ。私はshop_order投稿を全く照会できません! –