I am new to using add_rewrite_rule and add_rewrite_tag. I am trying to get a very basic example to work, but nothing I do seems to make it work.
I want to access this URL (this works when entering this URl in directly):
http://localhost/?author_name=rewrite
Via this URL:
http://localhost/name/rewrite
I have the following code in functions.php:
$wp_rewrite->flush_rules();
add_action( 'init', 'addMyRules' );
function addMyRules(){
add_rewrite_rule('^people/([^/]*)/?','index.php?author_name=$matches[1]','top');
add_rewrite_tag('%author_name%','([^&]+)');
}
But I keep seeing a 404 page. Not sure what I am doing wrong.
I am new to using add_rewrite_rule and add_rewrite_tag. I am trying to get a very basic example to work, but nothing I do seems to make it work.
I want to access this URL (this works when entering this URl in directly):
http://localhost/?author_name=rewrite
Via this URL:
http://localhost/name/rewrite
I have the following code in functions.php:
$wp_rewrite->flush_rules();
add_action( 'init', 'addMyRules' );
function addMyRules(){
add_rewrite_rule('^people/([^/]*)/?','index.php?author_name=$matches[1]','top');
add_rewrite_tag('%author_name%','([^&]+)');
}
But I keep seeing a 404 page. Not sure what I am doing wrong.
Share Improve this question asked Mar 30, 2014 at 13:21 fakeguybrushthreepwoodfakeguybrushthreepwood 2111 gold badge5 silver badges15 bronze badges1 Answer
Reset to default 1I simply changed it to this, and it works!
add_action( 'init', 'addMyRules' );
function addMyRules(){
add_rewrite_rule('^people/([^/]*)/?','index.php?author_name=$matches[1]','top');
add_rewrite_tag('%author_name%','([^&]+)');
flush_rewrite_rules();
}