1

I’ve used WordPress for years as a content admin but I am new to PHP development (am fine with HTML/CSS). From Googling about and experimenting I believe that what I want to achieve isn’t standard WordPress functionality, but it is so commonplace on sites I’m surprised I haven’t found a solution yet.

I have a Custom Post Type of ‘recipes’ and a Custom Taxonomy of ‘recipe_type’. I’m able to see a list of posts at /taxonomy/term/ , but the /taxonomy/ page produces a 404. I am using the Pods plugin to create these (and all custom fields) but there’s nothing being created that isn’t core WP i.e. no pods-specific stuff.

I would like to have a page at /taxonomy/ that lists the taxonomy terms e.g. ‘vegan’, ‘vegetarian’, etc. The user can then link through to the term pages through these.

I see this as the familiar setup on ecommerce sites where you’ll have /products/ as a landing page and then /products/product-type/ as the lists of items, for example /products/cameras/ or /products/televisions/ .

I have tried to set this up by having a taxonomy-recipe_type.php template and archive-recipes.php template concurrently. The archive lists the terms in a grid and the taxonomy template lists the posts correctly. However, I run into several issues:

  1. Permalink issues - archive appears at /recipes/ but the taxonomy pages appear at /recipe-type/.
  2. Enabling rewrite fixes this but then the posts don’t appear (404).
  3. This isn’t a very DRY approach - I’m having to use two templates just to get this setup, and I’d like to repeat this setup for other CPTs and Taxonomies.

This seems a very common thing to setup but I’m just running out of luck. How can I create a taxonomy template that checks if the user is currently on the root taxonomy page (i.e. example.com/taxonomy/) and then display a list of terms. Else, if they’re on a term page (i.e. example.com/taxonomy/term/) display the list of posts?

Thanks in advance!

0

After researching some more I've given up trying to use the taxonomy template and opted for a plugin to amend the permalinks. I followed some of the advice from this similar question: Taxonomy archive with same slug as custom post type?

Currently I am using an amended archive template for the custom post types and then the WP Better Permalinks plugin to rewrite the permalinks how I need them i.e. example.com/custom-post-type/custom-taxonomy/post-name/

If you need a simple solution this plugin works very well as far as I can tell. I also used Custom Post Type Permalinks which gives a greater level of control (this works the same way as the default WordPress permalinks settings, in that you can arrange the permalink tags in whichever way you like). The only reason I dropped this plugin is that it refused to work with one out of my five CPTs, even though everything was setup the same.

Hopefully this helps someone else in the future.

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.