Question

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?

Was it helpful?

Solution

The correct post status for published posts is publish. Post statuses are in present tense (So publish, not published, and draft, not drafted).

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top