I still don't quite understand when it's best to use custom post types vs custom taxonomies.. or both together at once. I have Menus as my custom post type. There's nothing about it that needs to look different from any other post on the site though. What I need to do is display a list of Types of menus (traditional, Indian, Kosher etc), and then below each type, a list of each post(menu) of that type. How is the best way to do this? I'd like to keep it in a separate section from the blog, and I love the custom menu item in the admin, so it's ideal that way. I'm just stuck on how to get essentially a "category" page (menus) that would list all the subcategories (types of menus) and all posts in those subcategories.


1 Answer 1


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).

// 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>";
    while ( have_posts() ) : the_post(); 

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

    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.

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.