WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've grouped my pages by some custom taxonomy. But I need to care about those without any taxonomy set. My code is:

$page_groups = get_terms('page_group'); //get all existing page groups
foreach ($page_groups as $page_group) { //for every of them
    $group_name = $page_group->name;    //get group name
    $loop = new WP_Query( array( 'post_type' => 'page', 'page_group' => $group_name ) );    //and loop for all pages from that category

    while ( $loop->have_posts() ) : $loop->the_post();

        //main stuff here


    wp_reset_query();   //reset loop
    rewind_posts();     //and rewind posts
} // End foreach $page_groups ?>

It works cool, but after that loop I want to display all the pages that has no 'page_group' taxonomy - only those. I've tried to query without taxonomy but it loops all the pages.

share|improve this question
What is page_group? Not seeing that as an available option in WP Query. get_terms() can retrieve the taxonomy by using $page_group->taxonomy which you could set in WP_Query – Zach Nov 30 '12 at 19:54
page group is custom taxonomy. the code i've pasted is working ok and it loops all groups and all posts of all grops. I need another loop that loops only posts that HAS ANY post_group taxonomy. – Adam Nov 30 '12 at 20:04

One solution would be to give a value of "none" to your posts without any post group, similarly as you have "uncategorized" posts in WP Categories.

Alternatively… I haven't checked it, but why don't you try to make another WP_QUERY like this:

new WP_Query( array( 'post_type' => 'page', 'page_group' => '' ) )
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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