5

How can I exclude child posts using wp_query? Given the following architecture:

  • parent 1
    • child 1
    • child 2
  • parent 2
    • child 3
    • child 4

I'd like to only return parent 1 and parent 2, and exclude child 1, 2, 3 and 4.

I've searched high and low for an answer to this question. Nothing surfaces.

3
  • 2
    posts don't usually have a hierachy - do you mean pages?
    – Michael
    Commented Aug 4, 2011 at 17:48
  • 2
    posts do have hierarchical capabilities. Commented Aug 4, 2011 at 18:05
  • @LeePeterson Yap it's true. With plugins like CPT UI you can create a custom post type and add the page-attribute to it to make them hierarchical.
    – Warface
    Commented May 6, 2014 at 11:48

1 Answer 1

19

use 'post_parent' => 0 in WP_Query to return only parent posts

3
  • As soon as I posted my question, I found the answer somewhere else online. Thank you for the correct response!! Commented Aug 4, 2011 at 18:06
  • but 'post_parent' only works with pages no? What about "posts" on categories?
    – eveevans
    Commented Feb 2, 2015 at 20:09
  • @eveevans please ask a new question to get specific help for what you are trying to achieve.
    – Scott
    Commented Feb 4, 2015 at 10:29

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.