1

It seems simple but I haven't found an answer....

I have a custom post type 'team' with a taxonomy 'department'

I have an archive page archive-team.php that shows all team posts.

When I need to show a department I want to use the same template, just with the taxonomy as a filter.

But it doesn't*. I could set up a page taxonomy-department.php identical to archive-team.php but this is wasteful and prone to error.

I've looked through the docs and I can't see where you can force the archive type for a taxonomy to go to the archive for that post type.

How?

If it's useful I'll post the functions that created the post type and taxonomy.

2
  • 2
    Have a look at this answer.
    – Milo
    Commented Dec 7, 2016 at 16:45
  • Thanks Milo, a bit to get my head around. -- add a filter for taxonomy_template -- write a function to test if it matches my taxonomy (department) -- deliver the archive-team template instead. Watch this space....
    – Chris Pink
    Commented Dec 8, 2016 at 8:27

1 Answer 1

4

Thanks for Milo's pointer

function department_template( $template = '' ) {

 if (is_tax('department') ) {
   $template = locate_template( 'archive-team.php' );
 }

 return $template;

}

add_filter( 'taxonomy_template', 'department_template' ); 

Worth noting this doesn't disturb the hierarchy if another taxonomy is involved, ie taxonomy-othertax.php is called correctly for taxonomy 'othertax'.

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