0

Having a lot of issues with a custom taxonomy. So far I've spent an hour and a half searching and trying different things. I've tried almost everything and it's got to the point where I think I'm code blind.

I have a CPT called businesses and a custom taxonomy called business-types. The client is going to be adding different business types to assign to posts within the CPT.

They have a section setup like so:

Businesses [Custom page template, which loops through the CPT and does stuff based on ACF values]. This is the parent item on the nav.

A dropdown on the nav has the custom taxonomies so people can only view businesses in one industry (Such as medical, construction, retail etc). When they click these it should show posts from the businesses CPT which have the corresponding business-types assigned to it.

I've got the taxonomy-business-types.php however the body class doesn't indicate it's using this template which I think could be doing something (Which according to the template hierarchy at WP, it should be doing.

I've googled everything I can think of, checked the codex, and still no luck. I've tried about 200 things I've come across on SO and none have worked so far. I have't had this issue before so I think I may be going mental having worked on this site solid for this week!

Any help and advice would be greatly appreciated.

Cheers,
Ash

  • Could you look at this diagram: Template files hierarchy. Maybe something is overriding your custom file? – Krzysztof Grabania Aug 12 '16 at 11:02
  • @KrzysztofGrabania I've checked that already to make sure I was getting the correct files, and as per that diagram, i should be... Which is why I'm a little confused! All other custom taxonomies I've seen have an underscore, not a hyphen for the name.... I don't think this will cause an issue but any thoughts on that? – AshboDev Aug 12 '16 at 11:06
  • I currently have number 2 in that list (taxonomy-{taxonomy}.php - none of the other files exist beside archive.php. As the client will be adding taxonomies over time, i would like it to use this template rather than one template for each term – AshboDev Aug 12 '16 at 11:11
  • But in your taxonomy name you have got dash, which means that WordPress treat types like term of business taxonomy (First case: taxonomy-{taxonomy}-{term}.php) – Krzysztof Grabania Aug 12 '16 at 11:12
0

As Template hierarchy says, there are 5 possible file names for displaying taxonomy:

  • taxonomy-{taxonomy}-{term}.php – If the taxonomy is sometax, and taxonomy’s term is someterm, WordPress will look for taxonomy-sometax-someterm.php. In the case of post formats, the taxonomy is ‘post_format’ and the terms are ‘post-format-{format}. i.e. taxonomy-post_format-post-format-link.php for the link post format.
  • taxonomy-{taxonomy}.php – If the taxonomy were sometax, WordPress would look for taxonomy-sometax.php.
  • taxonomy.php
  • archive.php
  • index.php

You wanted to achieve second case, but in your taxonomy name you have got dash (taxonomy-business-types.php). It means that WordPress will use this file only when taxonomy name will be business and term of this taxonomy will be types (first case).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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