Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a draft post with the author set to 5. User #5 is trying to view that draft on the front end using a WP_Query with the following arguments:

array {
  ["name"]=> "example-52f00a8ba19f4"
  ["post_status"]=> array {
    [0]=> "draft"
    [1]=> "private"
  }
  ["post_type"]=> "customlisting"
  ["posts_per_page"]=> 1
  ["author"]=> 5
}

The user trying to view this is user #5. They are trying to view their own draft post, so that they can publish it... (on the front end)

The SQL query that is available in $wp_query->request does in fact return the listing (screenshot from HeidiSQL). But it does not appear in $wp_query->posts, and it seems WP_Query is removing it after the actual SQL query.

How can I prevent WP_Query from removing this? I don't know where to look. I don't know why it's happening either :/

Update: It seems the query only fails if searching by post name. It works by post ID (post__in, rather).

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There is indeed processing in WP_Query which might prevent posts from displaying if they are not simply public.

Since there are several conditions there it is a little hard to guess why it fails in your specific case. It might be issue with how permissions are setup or some edge case (which querying for non-public posts is full of).

share|improve this answer
    
Yeah it seems to be a particular condition where you search by post name (slug). It does work if I specify the ID, and I may need to change the entire draft mode of this plugin if I can't find a way around that. –  RadGH Feb 4 at 20:42
    
To circumvent the issue in my last comment, I used $wpdb to look up the ID of the post by the slug, then did a query for the post ID directly. –  RadGH Feb 4 at 21:02

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.