WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to query some wordpress posts, they have a custom post status of closed.

When I run this query, they get returned despite their custom status being set to closed, even though I've asked for published:

$now = strtotime(date('d.m.Y H:i:s'));
$args = array(
    'post_type' => 'vacancy',
    'post_status' => 'published',
    'posts_per_page' => 1000,
    'orderby' => 'meta_value_num',
    'meta_key' => 'wpcf-closing-date',
    'meta_query' => array(
        array(
            'key' => 'wpcf-closing-date',
            'value' => $now,
            'compare' => '<=',
        )
    ),
);
$vacancies = new WP_Query($args);

I would have expected that only posts with the post_status of closed would have come back. Anybody any ideas why this is returning published posts?

share|improve this question
    
The correct post_status for a published post is "publish" not "published". codex.wordpress.org/Class_Reference/WP_Query#Status_Paramete‌​rs – Michelle 15 mins ago

The post_status closed is not part of the default post_status.

This custom post status is maybe add by a plugin or theme.

If you find register_post_status in your files, there are custom post status, and maybe an array to convert closed to pending or something else.

if not look for add_meta_boxes action.

You can also try to var_dump a closed post custom fields to see if it is not add to à custom meta field. If it's the case, you will get your publish posts by excluding them with meta_query parameter.

Hope it gives some hints!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.