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?

1584 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?

1584 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!

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by