这个WP_Query::have_posts
仅考虑current_post
和post_count
对象的属性(请参见Code Reference 了解更多详细信息)。事实上,这些在你的var_dump
:
["posts"]=> array(0) { } ["post_count"]=> int(0) ["current_post"]=> int(-1)
因此,可能查询参数不正确,您正试图查询数据库中找不到的内容。
您可以尝试直接在数据库中运行MySQL查询,以查看它是否匹配任何内容:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID
FROM wp_posts
INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id )
WHERE 1=1
AND wp_posts.ID IN
(12501,12502,12503,12506,12510,12513,12528,12529,12536,12557,12558,
12561,12565,12575,12576,12578,12587,12601,12602,12603,12604)
AND ( ( wp_postmeta.meta_key = \'_customer_user\' AND wp_postmeta.meta_value = \'10\' ) )
AND wp_posts.post_type = \'shop_order\'
GROUP BY wp_posts.ID
ORDER BY wp_posts.post_date DESC
LIMIT 0, 20
我会特别检查post id是否正确,以及它们是否有必要的post\\u meta和匹配的meta\\u值。