WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I want to create a custom template for my taxonomy customtax.

This is pretty simple, I just create a taxonomy-customtax.php in my theme directory.

Now, I'ld like to query a built-in category with one term of my custom taxonomy, like so:


The problem here is that Wordpress always uses the archive.php (or category.php I think) instead of my taxonomy-customtax.php template.

Is there a way to invert this behaviour?

share|improve this question
up vote 1 down vote accepted

You can tell WordPress what template file to use with the template_redirect hook.

add_action( 'template_redirect', 'wpse98738_taxonomy_redirect' );
function wpse98738_taxonomy_redirect() {
    if( 'x' == $customtax && 'y' == $category_name ) {
        include( get_template_directory() . '/taxonomy-customtax.php' );
        // if you're using a Child Theme, use the following line instead:
        // include( get_stylesheet_directory() . '/taxonomy-customtax.php' );
        exit; // so that WP quits looking for templates to load


Codex pages for:


get_template_directory() / get_stylesheet_directory()

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.