Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

    endwhile;

    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
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.