'chapters', 'style' => 'none', 'orderby' => 'meta_value_num', 'order' => 'ASC', 'meta_query' => array( array( 'key' => 'chapter-order', 'type' => 'NUMERIC', )), 'show_count' => 0, ); $chapters = get_categories($chapter_args); foreach ($chapters as $chapter) { $args = array( 'post_type' => 'comic', 'order' => $comic_order, 'nopaging' => true, "tax_query" => array( array( 'taxonomy' => "chapters", // use the $tax you define at the top of your script 'field' => 'term_id', 'terms' => $chapter->term_id, // use the current term in your foreach loop ), ), 'no_found_rows' => true, 'update_post_meta_cache' => false, 'update_post_term_cache' => false, ); $chapters_posts = get_posts($args); if ($chapters_posts) { echo '

' . wp_kses_data($chapter->name) . '

'; echo '
'; foreach ($chapters_posts as $comic) { setup_postdata($comic); echo ''; if (get_the_post_thumbnail($comic->ID) != '') { echo ''; echo get_the_post_thumbnail($comic->ID, 'thumbnail'); echo ''; } else { echo ''; echo ''; echo ''; } echo '
'; echo 'Posted on ' . wp_kses_data(date('F j, Y', strtotime($comic->post_date))) . ''; echo '
'; } // foreach($chapters_posts echo '
'; } // if ($chapters_posts ?>