1

I have created a custom post type (products), and at the moment I have 2 custom taxonomies (lips and eyes).

I can get the archive to show up for 'products', and I can get to the URL for the archive for the categories under 'lips', but I cannot get the archive to show for the taxonomies.

I have been through every question I can find, and I have checked the answers against what I have done, but for the life of me I can't figure out what is going wrong.

I have a taxonomy template, 'taxonomy-lips.php', but it just keeps defaulting back to my front-page.php template.

Here is my code for the post type:

function my_first_post_type() {

$args = array(
    
    'labels' => array(
        
        'name' => 'Products',
        'singular_name' => 'Product',
        
        ),
        
    'hierarchical' => true,
    'public' => true,
    'has_archive' => true,
    'menu_icon' => 'dashicons-list-view',
    'supports' => array('title', 'editor', 'thumbnail'),
    'rewrite' => array('slug' => 'shop-products'),
    'taxonomies' => array('lips', 'eyes'),
    
    ); 
    register_post_type('products', $args);
    }
    add_action('init', 'my_first_post_type');

And here is the code for my taxonomy:

    function my_first_taxonomy()
    {
    $args = array(
    
    'labels' => array(
        
        'name' => 'Lips',
        'singular_name' => 'Lips',
        ),
        
    'public' => true, 
    'hierarchical' => true,
    'rewrite' => array('slug' => 'lips'),
   
    
    );
    
    register_taxonomy('lips', array('products'), $args);

    }
    add_action('init', 'my_first_taxonomy');

I have reset the permalinks many times, and nothing changes.

Sorry, I know this question has been asked many times, I just can't figure out what I have done! I'm very new to all of this, so be gentle lol, I might not understand anything too complex!

7
  • "it just keeps defaulting back to my front-page.php template" - how did you know it's not actually taxonomy-lips.php? What is the URL of the page, is it like example.com/lips/category-slug?
    – Sally CJ
    Jun 10, 2021 at 0:37
  • Also, in the question, the register_post_type() is outside the my_first_post_type() function..
    – Sally CJ
    Jun 10, 2021 at 0:43
  • 1
    Yes, the URL I am using is as you put above. example.com/lips/category-slug. I can get to that one. I can't get to example.com/lips.
    – Siobhan M
    Jun 10, 2021 at 1:15
  • Hmmm, ok. I'll adjust that, although that doesn't seem to have had an effect on the post type. I can use that without issue.
    – Siobhan M
    Jun 10, 2021 at 1:16
  • Sorry that probably didn't answer your question properly. When I go to example.com/lips, the page doesn't show an empty screen as my template has no coding in it. It shows my front-page.php layout and coding. It did this initially for the post type page too, but after I reset the permalinks that part started working correctly. Not this time :(
    – Siobhan M
    Jun 10, 2021 at 1:29

1 Answer 1

2

I cannot get the archive to show for the taxonomies

And in the comments you said:

I can't get to example.com/lips

And similar to what I said here:

  • Taxonomies, unlike post types, do not have an archive page (which displays posts from all terms in the specific taxonomy), so it's normal if you "can't get to" example.com/lips or example.com/eyes, i.e. example.com/<taxonomy key>.

  • And secondly, taxonomy templates like taxonomy-lips.php actually rely upon the current taxonomy term, i.e. there has to be a term being queried in order for a taxonomy template to be used, and for functions like is_tax() to return true. So remember, the query determines the template and not the other way round. And for example example.com/lips/category-slug worked (i.e. taxonomy-lips.php was used) because there's a term being queried which is the one with the slug category-slug.

So no matter how many times you flush/regenerate the rewrite rules, taxonomies simply do not have an "all-terms" archive, only specific terms in the taxonomies. See @bosco's answer here if you're interested in knowing more tech stuff about taxonomy's "archive page", which by default do not exist or not implemented in WordPress core.

I hope this answered your question, and if all you wanted to have is for the example.com/lips and example.com/eyes to display posts from all/any terms in the lips/eyes taxonomy, then an easy way is:

  1. Create a custom Page (post of type page) and give it the lips or eyes slug.

  2. Assign a custom page template to that Page.

  3. And then make a secondary/custom WP_Query query in that very template.

4
  • Oh ok! That's really helpful thank you! My next challenge will be to figure out how to do all of that! So, if I can ask, how then would I make a 'cover page' effectively for each taxonomy. So for instance, this is a this will effectively look like a brochure. My custom post type was to hold all the products in it, but then sorted in sections (the taxonomies). Or so I thought. And then I thought the categories would be the way to get the specific products in the right places. I need to think about it a bit more I think...
    – Siobhan M
    Jun 10, 2021 at 2:54
  • I'm glad I could help, and remember, if an answer answered your question, consider marking it as correct (i.e. "accept" it as the "solution"). :) As for creating the custom all-terms taxonomy archive page, you can ask about it in a separate question - or just wait for the linked question (the one currently with a bounty) to be updated with new or revised answers.. ;)
    – Sally CJ
    Jun 10, 2021 at 3:10
  • What I had in mind, though, was: 1) In your template, use get_queried_object()->post_name to get the taxonomy key, and 2) Then make a new WP_Query in the template to query posts in any terms in the specified taxonomy key which is the Page slug.
    – Sally CJ
    Jun 10, 2021 at 3:20
  • But an easier way, without having to create the Pages (which is specifically helpful if you've got many taxonomies), is using custom URL rewriting. But then as I said, you should ask a new question in specific to that.
    – Sally CJ
    Jun 10, 2021 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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