I want to rewrite
mysite/events/submission/test-event-01
to
mysite/events/submission?epl=test-event-01
This is what I have done so far without any result. I get a 404 error (mysite/events/submission/test-event-01). Can anyone suggest the correct rule?
add_action( 'init', 'epl_rewrite');
add_filter( 'query_vars', 'epl_query_vars');
function epl_rewrite()
{
add_rewrite_rule('^submission/([^/]*)[/]?', 'index.php?pagename=submission&epl=$matches[1]', 'top');
}
function epl_query_vars( $query_vars )
{
$query_vars[] = 'epl';
return $query_vars;
}
Note:
- Permalinks are re-saved to flush the rewrite rules.
- mysite/events/submission page is already added.
Thank you in advance.
I want to rewrite
mysite.com/events/submission/test-event-01
to
mysite.com/events/submission?epl=test-event-01
This is what I have done so far without any result. I get a 404 error (mysite.com/events/submission/test-event-01). Can anyone suggest the correct rule?
add_action( 'init', 'epl_rewrite');
add_filter( 'query_vars', 'epl_query_vars');
function epl_rewrite()
{
add_rewrite_rule('^submission/([^/]*)[/]?', 'index.php?pagename=submission&epl=$matches[1]', 'top');
}
function epl_query_vars( $query_vars )
{
$query_vars[] = 'epl';
return $query_vars;
}
Note:
- Permalinks are re-saved to flush the rewrite rules.
- mysite.com/events/submission page is already added.
Thank you in advance.
Share Improve this question asked Feb 27, 2022 at 21:20 sariDonsariDon 2651 gold badge2 silver badges18 bronze badges 2 |1 Answer
Reset to default 0Since 'submission' is a child page of 'events', the rewrite rule should include the parent path
add_rewrite_rule('events/([^/]*)/submission/?', 'index.php?pagename=events/submission&epl=$matches[1]', 'top');
mysite.com/events/submission/test-event-01
to instead seemysite.com/events/submission?epl=test-event-01
then that's not a rewrite, that's a redirect. WP Rewrite rules are for mapping pretty URLs on to ugly URLs of the formindex.php?foo=bar
, they aren't redirects. – Tom J Nowell ♦ Commented Feb 27, 2022 at 22:51get_query_var
. – sariDon Commented Feb 28, 2022 at 5:12