I created a hierarchical custom post type for a gallery. The parent pages are the galleries and the child pages are the albums. I want to display the most recent albums on my sidebar (so basically the most recent child pages).
'post_parent' => 0
I only find this in the codex, but this is the opposite i want, this will only list the parent pages. Here is my code so far:
$albums = new WP_Query(array(
'post_type' => 'gallery',
'posts_per_page' => 6
));
Assuming you know (or know how to get) the
$id
(as an integer) of the parent post, use thepost_parent
parameter:Edit
Based on this comment:
While it is easy to query only parent pages (by passing
'post_parent' => 0
), it is not quite so simple to query only child pages.One method would be to query all
gallery
posts, loop through them, and add any that have apost_parent
into another variable; then output that variable.