我正在运行以下代码:
$posts = get_posts([
\'post_type\' => [\'my-type\', \'another-type\'],
\'numberposts\' => -1,
\'order\' => \'ASC\',
\'orderby\' => \'title\',
\'post_status\' => [\'published\',\'future\']
]);
它只返回数组中最后出现的状态。因此,在上面的示例中,它返回所有状态为的帖子
future
. 如果我交换订单,它只会返回
published
职位。
我设置了一个断点,并将参数传递给WP\\u Query(),它们如下所示:
Array
(
[numberposts] => -1
[category] => 0
[orderby] => title
[order] => ASC
[include] => Array
(
)
[exclude] => Array
(
)
[meta_key] =>
[meta_value] =>
[post_type] => Array
(
[0] => my-type
[1] => another-type
)
[suppress_filters] => 1
[post_status] => Array
(
[0] => published
[1] => future
)
[posts_per_page] => -1
[ignore_sticky_posts] => 1
[no_found_rows] => 1
)
我看到过状态和类型作为数组传递的示例。我做错了什么?
最合适的回答,由SO网友:Jacob Peattie 整理而成
已发布帖子的正确帖子状态为publish
. Post状态为现在时(Sopublish
, 不published
, 和draft
, 不drafted
).