69 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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?

1455 posts How's the surf doing?
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
  • Made it to the Authors' Hall of Fame
+6 more
tommusrhodus says

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

69 posts
  • Has been part of the Envato Community for over 5 years
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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?

1455 posts How's the surf doing?
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has been part of the Envato Community for over 3 years
  • Had an item featured on Envato Market
  • Made it to the Authors' Hall of Fame
+6 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
  • Has been part of the Envato Community for over 5 years
  • Has collected 100+ items on Envato Market
  • Sells items exclusively on Envato Market
  • Located in 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