using custom taxonomies with custom post types: display list of posts by ‘category’

I like to think of a custom post type as how you define the structure of your content, so menus is a perfect example of how to use a custom post type to structure your post data to be more like a menu.

Your need to categorize your menus into different types would be well met by a custom taxonomy. For how to do this, please see the codex entry for register_taxonomy()

Once you have your menu type custom taxonomy setup, and some menus assigned to the different menu types, it will be time to build a template file that presents the data as you wanted. I’m not sure this will be the best way, but it should work pretty well. You can start a new(or duplicate) template file, and call it archive-menus.php (presuming “menus” is the system name for the custom post type you made).

Now, in the main content area of your new archive template, copy and paste the following code that will get all terms from your custom taxonomy, and loop through them, displaying a list of menus under each taxonomy term(like a category).

<?php 
// change 'taxonomyName' to the system name of your custom taxonomy.
$terms = get_terms('taxonomyName', array(
    'orderby' => 'name',
    'order' => 'ASC'
));
echo "<ul id='menu-types'>";
foreach($terms as $term) {
    $termSlug = $term->slug;
    echo "<li><h2>".$term->name."</h2><ul>";
    query_posts('post_type=menus&taxonomyName=".$termSlug);
    while ( have_posts() ) : the_post(); 

                 echo "<li>".get_the_title()."</li>"; 

    endwhile;
    echo "</ul></li>";
}
echo "</ul>";
 ?>

Presuming your custom taxonomy is set up properly, and both instances of “taxonomyName’ in the ^^^above code were edited to reflect your custom taxonomy name, then the loop should display the data you need. Using “pretty” permalinks you should be able to link to the archive-menus.php template with a url like http://yoursite.com/menus. Just be sure that where you register_post_type() in your functions.php file, you have set the 'has_archive' => true, option.