1

My WP query to fetch some custom posts should exclude private posts, but this query is returning all posts, not just public ones:

$wp_query = new WP_Query( 'post_type=listing&post_status!=private&posts_per_page=9&meta_key=location_level1_value&orderby=location_level1_value&order=ASC&paged='.$paged);

I've also tried using post_status=-private, but that didn't work either...

What have I done wrong?

1 Answer 1

4

I have to wonder if post_status=public would successfully exclude. That way it's just targeting the public posts.

4
  • It does, except then I also include empty "Auto Draft" posts Oct 18, 2010 at 23:07
  • 2
    But post_status=publish does the trick... thanks Oct 18, 2010 at 23:14
  • 2
    Except that post_status=publish WILL include private posts if the user happens to be logged in.
    – David
    Jan 16, 2013 at 19:35
  • @David actually 'post_status' => 'publish' works perfectly for me. It does exclude private posts even when logged in.Tested on older WP 4.9.15 though, not sure how it will behave on the newest releases. Jun 15, 2020 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.