I am trying to created new rewrite rules for sth like this
www.myweb/question/#comments-2345
where 'question' is TAG and the #comments-2345 suppose to be recognized and read by get_query_var. '#comments-" is always constant string and the 2345 depends on the comment number in db. code
add_rewrite_tag('%question%', '([^&]+)');
add_rewrite_rule('^question/([^/]*)/?','index.php?page_id=77&question=$matches[1]','top');
and i read the the variable as
$hpytanie= get_query_var( 'question' );
But something does not work, the get_query_var gives empty. Any advice why it does not work?
thanks
I am trying to created new rewrite rules for sth like this
www.myweb/question/#comments-2345
where 'question' is TAG and the #comments-2345 suppose to be recognized and read by get_query_var. '#comments-" is always constant string and the 2345 depends on the comment number in db. code
add_rewrite_tag('%question%', '([^&]+)');
add_rewrite_rule('^question/([^/]*)/?','index.php?page_id=77&question=$matches[1]','top');
and i read the the variable as
$hpytanie= get_query_var( 'question' );
But something does not work, the get_query_var gives empty. Any advice why it does not work?
thanks
Share Improve this question asked Oct 24, 2018 at 8:15 Greg SkalaGreg Skala 8110 bronze badges 11 | Show 6 more comments1 Answer
Reset to default 0Try adding a query var
add_filter('query_vars', 'foo_my_query_vars');
function foo_my_query_vars($vars){
$vars[] = 'question'; return $vars;
}
get_query_var()
works on query strings only, and not URL hash like that. – Sally CJ Commented Oct 24, 2018 at 8:25