Skip to main content
1 of 3
Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118

This isn't tested, but try (after you added the code you'll need to go to settings> Permalinks and click save for it to take effect):

add_action('generate_rewrite_rules', 'my_rewrite_rules');
function my_rewrite_rules( $wp_rewrite ) {
  $new_rules = array(
     '(.+)/year/(.+)' => '?cat='.$wp_rewrite->preg_index(1).'&year='.$wp_rewrite->preg_index(2),
       );

  // Add the new rewrite rule into the top of the global rules array
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}

That should take: http://yourwebsite.com/foobar/year/2011 and return results in category foobar, in 2011.

I'm not sure that structure is the the best way to go about it. To avoid unwanted issues, I would suggest using: http://yourwebsite.com/category/foobar/year/2011 and use instead:

'category/(.+)/year/(.+)' => '?cat='.$wp_rewrite->preg_index(2).'&year='.$wp_rewrite->preg_index(2)

Hope this helps!

Stephen Harris
  • 32.6k
  • 6
  • 84
  • 118