I’m making an attempt to comply with the examples within the wordpress documentation about add_rewrite_rule and add_rewrite_tag.
I am utilizing a customized submit sort referred to as “panel“.
so the pages appear like “web site.com/panel/post-slug“
url queries work: for instance I’ve 2:
var1 and testquery.
if I’m going to “/panel/test-page-auto/?var1=10“
And with var1 and testquery:
so what i would like is, change the /panel/test-page-auto/?var1=10&testquery=Hello
-> /panel/test-page-auto/10/Hiya
my code:
add_action('init', '__rewrite_tag_rule', 10, 0);
operate __rewrite_tag_rule() {
/**
* check web page tag rute
*/
$page_type = "^panel/";
add_rewrite_tag('%testquery%', '([^&]+)');
add_rewrite_tag('%var1%', '([^&]+)');
//Add rule
//panel/test-page-auto/10/edit
add_rewrite_rule(
$page_type."test-page-auto/([^/]*)/([^/]*)/?",
'index.php?pagename=test-page-auto&var1=$matches[1]&testquery=$matches[2]',
'high' );
//add rule for present
//panel/test-page-auto/10
add_rewrite_rule(
$page_type."test-page-auto/([^/]*)/?",
'index.php?pagename=test-page-auto&var1=$matches[1]&testquery=100edit',
'high' );
}
add
_filter(‘query_vars’, operate($vars) {
$vars[] = “testquery”;
$vars[] = “var1”;
return $vars;
});
However it’s not working.
when I attempt to put /panel/test-page-auto/10/Hello it simply redirects me to /panel/test-page-auto and the queries are clean.
Can somebody assist me perceive what I am doing flawed?
I’ve already tried:
- save permalinks after every change.
- edit the principles in numerous methods.
- check the hyperlinks utilizing the queries and they’re working.