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.
page_group
? Not seeing that as an available option inWP Query
.get_terms()
can retrieve the taxonomy by using$page_group->taxonomy
which you could set inWP_Query