I'm developing a WP plugin and have a WordPress URL:
(e.g.: http://localhost/testsite1/coder/?id=66
),
and have attempted to add a rewrite rule to
http://localhost/testsite1/coder/66/
using the following rule:
function add_mypage_rule(){
add_rewrite_rule(
'^coder/([0-9]+)',
'index.php?id=$matches',
'top'
);
}
add_action('init', 'add_mypage_rule');
I have registered a WP Query Var using:
add_filter('query_vars', 'registering_custom_query_var');
function registering_custom_query_var($query_vars){
$query_vars[] = 'id';
return $query_vars;
}
but when at URL http://localhost/testsite1/coder/66/
, when I run code
echo get_query_var('id');
nothing is displayed
however when at URL http://localhost/testsite1/coder/?id=66
the echo statement will display 66
.
What is wrong with my rewrite rule resulting in echo get_query_var('id');
not accessing the parameter and displaying 66?