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.

  • 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, 2012 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, 2012 at 20:04

1 Answer 1


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' => '' ) )

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.