3

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.

  • 2
    posts don't usually have a hierachy - do you mean pages? – Michael Aug 4 '11 at 17:48
  • 2
    posts do have hierarchical capabilities. – Lee Peterson Aug 4 '11 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 May 6 '14 at 11:48
12

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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