Basically I want to rewrite: /edit/test-post to an existing page with a parameter: /edit?e=test-post
From the examples in the Codex I created:
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
add_action( 'wp_loaded','my_flush_rules' );
// flush_rules() if our rules are not yet included
function my_flush_rules(){
$rules = get_option( 'rewrite_rules' );
if ( ! isset( $rules['(edit)/(\d*)$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// Adding a new rule
function my_insert_rewrite_rules( $rules )
{
$newrules = array();
$newrules['(edit)/(\d*)$'] = 'edit?&e=$matches[2]';
return $newrules + $rules;
}
// Adding the id var so that WP recognizes it
function my_insert_query_vars( $vars )
{
array_push($vars, 'e');
return $vars;
}
However, I simply cannot get it working, what am I doing wrong?
Thanks!
e=
parameter value to be a string or digits? In your question intro it's a string/slug, but in the code your pattern(edit)/(\d*)$
would match 'edit' and then digits.