Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WordPress WP_Query - Query parent pages only

Tags:

wordpress

I'm using a WP_Query to query my custom post type posts. This custom post type has parent and children pages. I'm trying to pull the first parent page. How would I do this?

like image 549
cqde Avatar asked Mar 24 '11 04:03

cqde


1 Answers

$parent_only_query = new WP_Query(array(
    'post_type' => 'my-custom-post-type',
    'post_parent' => 0
));

while ($parent_only_query->have_posts()){
    $parent_only_query->the_post();
    // etc...
}

wp_reset_query(); // if you're not in your main loop! otherwise you can skip this
like image 136
Tom Auger Avatar answered Oct 15 '22 11:10

Tom Auger