I am running the following code:
$posts = get_posts([
'post_type' => ['my-type', 'another-type'],
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'title',
'post_status' => ['published','future']
]);
It is only returning the status that appears last in the array. So in the above example it returns all posts with status future
. If I swapped the order it would return only the published
posts.
I set a break point and get the args being passed to WP_Query() and here they are:
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
)
I have seen examples where the status and type is passed as an array. What am I doing wrong?
I am running the following code:
$posts = get_posts([
'post_type' => ['my-type', 'another-type'],
'numberposts' => -1,
'order' => 'ASC',
'orderby' => 'title',
'post_status' => ['published','future']
]);
It is only returning the status that appears last in the array. So in the above example it returns all posts with status future
. If I swapped the order it would return only the published
posts.
I set a break point and get the args being passed to WP_Query() and here they are:
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
)
I have seen examples where the status and type is passed as an array. What am I doing wrong?
Share Improve this question edited Apr 18, 2020 at 4:30 Guerrilla asked Apr 18, 2020 at 4:17 GuerrillaGuerrilla 4156 silver badges20 bronze badges1 Answer
Reset to default 2The correct post status for published posts is publish
. Post statuses are in present tense (So publish
, not published
, and draft
, not drafted
).