69 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • United Kingdom
will1234craig says

I am having trouble trying to query a single private post. I have created a custom post type called dogs, some of which are published and some of which are private.

I can query all of the dogs using the following code:

$args = array ('post_type' => 'dog', 'post_status' => array('publish', 'private')); $male_q = new WP_Query($args);

However, if I specify a name, for example:

$args = array ('post_type' => 'dog', 'name' => 'bouncer', 'post_status' => array('publish', 'private')); $male_q = new WP_Query($args);

then the query returns nothing.

Any thoughts?

1190 posts How's the surf doing?
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 3-4 years
  • Envato Studio (Microlancer) Beta Tester
+1 more
tommusrhodus says

Instead of ‘name’ try the post__in method outlined in the WP Codex

69 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • United Kingdom
will1234craig says

I tried that along with p, page_id, pagename etc. Whilst they work when the page is published, they do not work when it is private. Do you think this could be a WordPress issue?

1190 posts How's the surf doing?
  • Elite Author
  • Sold between 250 000 and 1 000 000 dollars
  • United Kingdom
  • Referred between 200 and 499 users
  • Exclusive Author
  • Has been a member for 3-4 years
  • Envato Studio (Microlancer) Beta Tester
+1 more
tommusrhodus says

Do the publish & private settings conflict with one another? Perhaps you could try querying only the private meta.

One thing to consider though, if you’re going as far querying a post by specific ID, then why do you need to add the publish/private query also? As long as you’re querying an ID it will only ever return 1 post anyway. Just something to consider :)

69 posts
  • Bought between 100 and 499 items
  • Exclusive Author
  • Has been a member for 5-6 years
  • United Kingdom
will1234craig says

If I take away the ID all of the private posts will appear but I need only one specific ID to show. The reason I have to add the private query is because by default WordPress won’t show include private posts in query results. Thanks for your help but looks like there isn’t a simple solution for this!

by
by
by
by
by
by