0

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 published would have come back. Anybody any ideas why this is returning closed posts?

2

The correct post_status for a 'published' post is 'publish':

'post_status' => 'publish',
  • Good catch Michelle ! – Benoti Nov 22 '16 at 20:07
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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