0

I have a custom post type, named 'products', it has a custom taxonomy that is called 'collections'.
This is how I have registered the taxonomy.

$productTaxonomyArgs = [
    'public' => true,
    'publicly_queryable' => true,
    'show_ui' => true,
    'show_in_menu' => true,
    'show_admin_column' => true,
    'description' => __('Product category', 'byronposttypes'),
    'hierarchical' => true,
    'rewrite' => [
        'slug' => __('collections', 'byronposttypes'),
        'with_front' => true,
        'hierarchical' => true,
        'ep_mask' => EP_CATEGORIES
    ],
];

register_taxonomy('collections', 'products', $productTaxonomyArgs);
register_taxonomy_for_object_type('collections', 'products');

I have created a taxonomy template by the name taxonomy-collections.php.

<?php

get_header();
$post = null;
echo '<h1>taxonomy-collections.php</h1>'; //Echo this to make sure the template works.
if (have_posts()) {
    while (have_posts()) { //rest of the code

When I navigate to /collections/lifestyle (lifestyle is one of the taxonomy terms), the <title> is 'Lifestyle Archives - [sitename]', so Wordpress does recognise the url as a taxonomy term archive. The problem is, that it doesn't even echo <h1>taxonomy-collections.php</h1> to the page. That makes me assume that the taxonomy-collections.php is not recognised by Wordpress.
Any idea as to what I am doing wrong? Thanks a lot for reading and helping!
I found out that Wordpress is falling back to index.php. But is_tax(); returns true. Not a single one of the taxonomy-specific templates seem to work (taxonomy.php, taxonomy-collection.php and taxonomy-collection-lifestyle.php), not even archive.php will work.

  • have you tried flushing permalinks?? Go to wordpress settings and save permalinks. – Harry Mar 30 '17 at 8:09
  • I have, this does not solve my problem. Navigating to /collections/lifestyle sets the page title to 'Lifestyle Archive', which I think would imply Wordpress using the right rewrite rules. Even using taxonomy.php does not work. – Connor Mar 30 '17 at 8:14
  • If you check the body classes what does it show? This usually gives away which file is being loaded – Jeffrey von Grumbkow Mar 30 '17 at 11:06
  • It shows the following classes: archive tax-collections term-lifestyle term-99 logged-in wpb-js-composer js-comp-ver-5.0.1 vc_responsive. I also tried creating archive.php to see if that would work, but that also had no effect. The header and footer are included when loading the page – Connor Mar 30 '17 at 11:27
  • I have found out that Wordpress falls back to index.php (should've tested that earlier). I've edited my question to reflect this. – Connor Mar 30 '17 at 11:43
1

I just found out what I was doing wrong. Apparently you have to place archive pages in the root folder of your theme.
I placed them in a subfolder called templates. This works for page templates with a template name, but not for taxonomy.php, archive.php, single.php etc.

-1

Try this code, its working for me ..

 function add_collection_taxonomies() {
        $productTaxonomyArgs = array(
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'show_admin_column' => true,
        'description' => __('Product category', 'byronposttypes'),
        'hierarchical' => true,
        'rewrite' => array(
            'slug' => __('collections', 'byronposttypes'),
            'with_front' => true,
            'hierarchical' => true,
            'ep_mask' => EP_CATEGORIES
        ),
    );
    register_taxonomy_for_object_type('collections', 'products');
    register_taxonomy('collections', 'product', $productTaxonomyArgs);
  • 1
    Thanks for your input, but it doesn't seem to change anything, taxonomy-collections.php still does not seem to work as a template file. The only differences I see between our code snippets is that you use array in stead of [ ], and you switched around register_taxonomy_for_object_type() and register_taxonomy(). Did I miss something? I did re-save the permalinks after trying this, by the way – Connor Mar 30 '17 at 10:05

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.