Need help with rewrite_rules_array

I have a page that I access at /category/tasks and the file is located at wp-content/themes/my-theme/tasks.php. I would like to make it so I can add a flag after tasks and pick up the query strong in tasks.php. This works fine when I access the page with /category/tasks/?when=upcoming.

Can someone tell me how to use rewrite_rules_array so it will send the variable through the query string using the URL structure /category/tasks/upcoming?

3 Answers
3

Try this:

function when_rewrite_rules( $wp_rewrite ) {
  $new_rules = array();
  $new_rules['category/tasks/(\d*)$'] = 'index.php?when=$matches[1]';
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
add_filter('generate_rewrite_rules','when_rewrite_rules');

Leave a Comment