The site I'm working on has a very specific permalink structure, one that is very different from the default wordpress permalinks. I don't want to add rules; I want to replace the rules entirely with my own custom array of rules.
Below is some quick and dirty testing code. (This is not production code, I know not to flush the rules on every page.) This code is located in my theme's functions.php.
/**
* Flush the rules. Just for testing.
*/
function example_flush_rewrite_rules() {
global $wp_rewrite;
flush_rewrite_rules(); // Calls the function below
print_r($wp_rewrite->rules); // Does not display my rules, shows default rules
}
add_action('init', 'example_flush_rewrite_rules');
/**
* Overwrite the rewrite rules.
* This does not work. :(
*/
function example_generate_rewrite_rules($wp_rewrite)
{
global $my_custom_rules_array;
$wp_rewrite->rules = $my_custom_rules_array;
}
add_action('generate_rewrite_rules','example_generate_rewrite_rules');
Both function are called correctly, but the rules don't change after loading the page. How do I overwrite the contents of wp_rewrite and the rewrite rules? What am I doing wrong here? Thank you!
Aucun commentaire:
Enregistrer un commentaire