How To Flush Permalink Structure in WordPress When Using custom Taxonomies …or what to do when WordPress custom Taxonomies show A 404 Page

I have faced many times that permalink for custom taxonomy wont work, rather it shows a 404 error page.
Suppose you have custom taxonomy named as video and want to display a link as http://www.yoursite.com/videos but it shows page not found. I have listed some of the ideas to make that workable:

We can create and/or register custom taxonomies like following. We may have multiple taxonomies.

<?php
add_action('init', 'create_custom_taxonomy');
function create_custom_taxonomy (){
  register_taxonomy(videos,
    'post',
    array(
      'hierarchical' => false,
      'label' =>Videos ',
      'query_var' => videos,
      'rewrite' => array('slug'=>videos)
    )
  );
}
?>

In theme directory we can create a php file as “taxonomy.php” or “taxonomy- videos.php” file. This will handle the custom taxonomy requests. We can get the idea of creating different taxonomy templates from http://codex.wordpress.org/Template_Hierarchy.
To make the taxonomy permalink workable we can follow the following points:
Visit the Admin >> Settings >> Permalinks and click on save changes
Or
In functions.php file inside your theme put the below code:

<?php
add_action('init', 'custom_taxonomy_flush_rewrite');
function custom_taxonomy_flush_rewrite() {
	global $wp_rewrite;
	$wp_rewrite->flush_rules();
}
?>

Sometime the first method only doesn’t work and we need to work in both ways.
Some of the ideas from:
http://seanbehan.com/programming/how-to-flush-your-permalink-structure-in-wordpress-when-using-taxonomies-or-wordpress-taxonomies-not-working-instead-i-see-a-404-page/

Comments

comments

2 Comment

  1. anmari says: Reply

    Vinay,

    one should not advise people to flush on every page load (eg: on init) – could slow down teh whole website.

    See
    http://codex.wordpress.org/Rewrite_API/flush_rules

  2. Irvan says: Reply

    I was a long time looking for it ..
    permalink issue is confusing to me ..
    but I find the right solutions and work on my web
    thank you for this great article.

Leave a Reply