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).


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).

| 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. – Radley Sustaire Feb 4 '14 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. – Radley Sustaire Feb 4 '14 at 21:02

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.