How To Flush Your Permalink Structure in WordPress When Using Taxonomies …or WordPress Taxonomies Not Working Instead I See A 404 Page

I didn’t know this, but because of a linking problem using custom taxonomies in WordPress, I was forced to find out. If you create a new taxonomy, it will not work immediately on the front facing end. Your users will be greeted by a 404, page not found instead. This isn’t ideal for obvious reasons.

You create and/or register custom taxonomies like so. You may have multiple taxonomies.

add_action('init', 'create_my_taxonomy', 0);
function create_my_taxonomy(){
  register_taxonomy( 'musicians',
    'post',
    array(
      'hierarchical' => false,
      'label' => 'People who play lovely music that I like...',
      'query_var' => 'musicians',
      'rewrite' => array('slug'=>'musicians')
    )
  );
}

In your theme directory you need at “taxonomy.php” file. This will catch your custom taxonomy requests. You can get even more fancy and create a file like so “taxonomy-musicians.php” which you can use to differentiate your taxonomies look/feel. Nice and slick… however, you may be frustrated after following these two steps and be greeted with a friendly 404 page not found template instead.

Fear not, you need only visit the Admin >> Settings >> Permalinks page as a logged in admin to flush your rewrite rules and get linking and your correct custom taxonomy template file. Straight forward, unless if you didn’t know that merely visiting the Permalinks Settings page would correct the problem. But Alas, you do!

Addendum

You must also have posts using the taxonomy! Otherwise, you will still get the page 404 not found! I’m not sure if there is a work around for this at the moment. Anyone know?

  • http://www.asianextreme.net AsianExtremeNet

    very useful tip, thank you.

  • http://www.mattnortham.com Matt Northam

    This had been puzzling me for days until I stumbled on this.. I was *this* close to giving up bothering with it at all – so thanks for making this post. Such a simple ‘fix’ for such an odd problem.

  • Trangsene

    Ouah, I’ve lost hours on this ! Until I find your post. So thanks a lot !

  • http://www.digitalprojects.co.za/ Sean

    Brilliant, this was driving me nuts. Thanks for the solution!

  • http://www.kodmobi.com abdessmamad idrissi

    thanx Sean, you saved me lots of headaches!

    this is a unique tutorial since all the taxonomy-tutorials don’t tell you this small detail.

    wordpress taxonomy page reference don’t montion that.. i’ll add a link to your post

    thanx again :)

  • http://offsetmedia.co.uk GeoNeo

    ahhh thank you!

  • Adriaan

    Thank you sooo much for this. I was struggling with this for about an hour and got really frustrated.

    I went to the admin > settings > permalinks as you’ve mentioned and everything works…sweet!!!

  • Molly

    Thanks a lot! This was driving me crazy…

  • Mathis

    Thank you!!

    This was driving me crazy, too…

  • http://priostudio.co.cc Sisir

    Install some sharing button dude!

    • bseanvt

      Just did. Thanks for the reminder!

  • http://www.solarmonster.co.uk/ Solar Monster

    I have done this, with a custom post type named ‘question’, a rewrite of that pointing to /knowledge-base/faqs

    Then I also have a custom taxonomy called question_category, with the same rewrite base as above, therefore a question, say ‘Question-1′ would have a slug of /knowledge-base/faqs/question1, which works fine (I have a single-question.php set up).

    If I click on to the taxonomy that it belongs to, I just get a 404 page, but the URL works fine (knowledge-base/faqs/tag-one/)

    I have a taxonomies.php file… Is there anything above and beyond the archives.php template I should put in there?

    Any help/suggestions would be appreciated!

  • http://www.developingelegance.com Tim Mahoney

    Thanks for this – damn thing was coming up 404 and I couldn’t for the life of me figure out how to fix it.

  • Daniel

    Hi Sean.
    Congrats with your blog!
    We’re facing these problem:

    we created the taxonomy ‘autores’ attached do the post type ‘discos’.

    we are actually having the same 2nd page 404 error,
    when browsing from the query for ‘autores’ to the second page we go to 404.

    here’s the code.
    Hope you can help:

    - – - – - – - – - – - -

    $term = get_term_by( ‘slug’, get_query_var( ‘term’ ), get_query_var( ‘taxonomy’) );
    $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;

    $args1 = array(
    ‘post_type’=>’discos’,
    ‘autores’ => $term->slug,
    ‘posts_per_page’ => 5,
    ‘paged’ => $paged,
    );

    query_posts($args1);

    - – - – - – - – - – - -

    And if the answer is the same as you gave in your post,
    what exactly should i write in the Admin >> Settings >> Permalinks page ???

    Thank you very much,
    hope you or someone can help us!
    best regardas

  • http://buyfestivaltickets.co.uk/bloodstock/ Bloodstock Tickets

    Thanks, this will reduce me some lines.

    -Joe

  • http://photocooker.blogspot.com Matias

    Wow! For hours I wondered and pondered why I was getting 404, until I found this site and visited the Permalinks page. Thanks a bunch!

  • http://www.sotvoril.ru Alex

    Thank you so much!
    I almost loose my mind figting this WP bug

  • http://www.bwebsites.co.uk Chris

    Thanks, I think you saved me a few hours of head banging frustration!

  • http://www.mmofront.com Sol

    Ahh so that’s what’s causing the error. I thought it was weird that it worked before but not now. You saved me many hours of pointless debugging. Thanks! =)

  • http://www.mayersdesign.com Tom

    I end up back here every time I forget this :’( cheers!