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.
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?
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
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!
- 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.