Archives by both date and category
-
hello!
I’m trying to figure out how to have a working permalink structure like:
site.com/category/catname/date/2010/04
I found this code snipplet here: https://snipplr.com/view.php?codeview&id=17432
function extend_date_archives_flush_rewrite_rules(){ global $wp_rewrite; $wp_rewrite->flush_rules(); } add_action('init', 'extend_date_archives_flush_rewrite_rules'); function extend_date_archives_add_rewrite_rules($wp_rewrite){ $rules = array(); $structures = array( $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_date_permastruct(), $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_month_permastruct(), $wp_rewrite->get_category_permastruct() . $wp_rewrite->get_year_permastruct(), ); foreach( $structures as $s ){ $rules += $wp_rewrite->generate_rewrite_rules($s); } $wp_rewrite->rules = $rules + $wp_rewrite->rules; } add_action('generate_rewrite_rules', 'extend_date_archives_add_rewrite_rules');
and it does the job but is eating ~4 queries per page load, deleting and reinserting the rewrite_rules key in the options table on every page.
There are more efficient ways to achieve this?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Archives by both date and category’ is closed to new replies.