I'm currently having a small issue with add_rewrite_rule
and can't seem to find any similar issues on stack overflow (even though there seems to be a lot).
It works fine for every URL I try:
profile/0/
profile/2/
profile/12313131/
I'm able to get the variable easy enough using $wp_query->query_vars['pid']
But if I try:
profile/1/
it always redirects to profile/
This is the only value that won't work. I can work around this if need be but wondering why this is the case? This is the first time I've had to use add_rewrite_rule
and I normally just use htaccess
.
Any help would be greatly appreciated.
The code I'm using is:
function profile_rewrite() {
add_rewrite_tag('%pid%', '([0-9]+)');
add_rewrite_rule('^profile/([0-9]+)/?', 'profile/?pid=$1', 'top');
}
add_action( 'init', 'profile_rewrite', 10, 0 );