I'm working on my own wordpress theme for the first time. I registered a new post type with custom taxonomy, but I can't display the posts by terms. I duplicated the archive.php and renamed it to taxonomy-[mycustomtaxonomy].php and modified few lines.

I left the loops as it exists in the archive.php:

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<?php the_content(); ?>

<?php endwhile; endif;  ?>

What's wrong with my code? How can I create a page like category.php?

UPDATE: Options for the custom taxonomy

$rewrite = array(
        'slug'                       => 'mmcat',
        'with_front'                 => true,
        'hierarchical'               => false,
    $args = array(
        'labels'                     => $labels,
        'hierarchical'               => true,
        'public'                     => true,
        'show_ui'                    => true,
        'show_admin_column'          => true,
        'show_in_nav_menus'          => false,
        'show_tagcloud'              => true,
        'rewrite'                    => $rewrite,
  • Yes, I flushed it. When I open the domain.com/mmcat/term the content inside the loop doesn't load. I have an empty container. May 20, 2015 at 13:01
  • Turn on error reporting in the wp-config.php file to see if any errors are being spit out.
    – Ty Bailey
    May 20, 2015 at 13:04
  • Add var_dump( $wp_query ); at the top of your taxonomy template and look at the main query object and what is actually returned. Turn debug on as well and check for obvious errors. Make sure that you problem is not caused by some rewrite function or custom filter or a plugin. The best will be is to disable all plugins and switching to a bundled theme to check the behavior there as well May 20, 2015 at 13:13
  • It does seem like there might be some syntax error on your template May 20, 2015 at 13:14
  • 3
    endif and endwhile should be reversed. They're in the wrong order in your code. The while is in the if, so is should be endwhile; endif; May 20, 2015 at 13:39

2 Answers 2


You should follow appropriate naming convention (aka Template Hierarchy) of your templates to make your job done.

If I'm clear about your query here then I'd suggest you to name your custom taxonomy archive template(s) as "taxonomy-{your-taxonomy-name-here}.php" (i.e. taxonomy-vegetable.php, taxonomy-fruit.php and so on)

There must not be any blank space or underscore between two words in your template names. Instead, you must write dash/hyphen between words.

But before your custom taxonomy archive page to function properly you should have your two more templates necessarily exist in your theme directory.

Those are "single-{your-custom-post-type-name}.php" and "content-{your-custom-post-type-name}-single.php" those follow respectively standard "single.php" and "content-single.php" if you're using your custom taxonomies with your custom post type(s). If you have "market" type then your templates should be "single-market.php" and "content-market-single.php"

In your "single.php", you'd probably see that there was something like <?php get_template_part( 'content', 'single' ); ?> and for this to work right there should be "content-single.php" template in your theme directory.

For your custom part, you'd write <?php get_template_part( 'content', 'market-single' ); ?> and would put your template specific code in your "content-market-single.php" file. And again, for your custom taxonomy archive(s) to work you'd build "taxonomy-shop.php" or "taxonomy-vegetable.php" template files.

Now, you can test if your "content-market-single.php" or "taxonomy-shop.php" is working properly by simply putting some normal texts like "hello/hi" on an empty white page (saved and naming with appropriate template name) and then running it by opening up one of your custom post or custom taxonomy term from your navigation menu or from your WordPress dashboard to your browser. If everything goes right then you can proceed on with your template building process.

You may find the following article very helpful because it's very much relevant to your query: http://www.smashingmagazine.com/2014/08/27/customizing-wordpress-archives-categories-terms-taxonomies/

  • The template file name is ok, because it loads. I have problem with the loop. May 20, 2015 at 16:50
  • @user1452062 "single-{your-post-type-name}.php" holds the loop (from while to endwhile) and whatever you put in your "content-{your-post-type-name}-single.php" template that is injected to "single-{your-post-type-name}.php" template while WordPress is loading that custom type single post. In that case you don't need to be worried about the loop inside the earlier template I mentioned above rather you need to put or organize your content of the loop in the later template hence "content-{your-post-type-name}-single.php". May 20, 2015 at 17:16
  • My loop is inside the taxonomy-xy.php and it not works. This post is not about 'how to organize' code. May 20, 2015 at 17:19
  • @user1452062 Then where is your existing code for taxonomy-xy.php?? I don't think you're getting any appropriate answer until you provide with minimum details from your relevant template. May 20, 2015 at 17:26
  • Please read my question, everything is in that. My problem is there is no result for my loop in the taxonomy template. The single, archive pages are working, even the taxonomy-[mytaxonomy].php May 20, 2015 at 17:32

The problem was with exclude_from_search parameter when I registered the post type.

exclude_from_search (boolean) (importance) Whether to exclude posts with this post type from front end search results.

    Default: value of the opposite of public argument 

    'true' - site/?s=search-term will not include posts of this post type.
    'false' - site/?s=search-term will include posts of this post type.

Note: If you want to show the posts's list that are associated to taxonomy's terms, you must set exclude_from_search to false (ie : for call site_domaine/?taxonomy_slug=term_slug or site_domaine/taxonomy_slug/term_slug). If you set to true, on the taxonomy page (ex: taxonomy.php) WordPress will not find your posts and/or pagination will make 404 error...

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.