admin管理员组文章数量:1130349
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;
}
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- try this link without # – Pravin Work Commented Oct 24, 2018 at 8:19
- www.myweb/question/comments-2345 – Pravin Work Commented Oct 24, 2018 at 8:20
- it has to be with #, as this is the comment structure format. This page has comments, and if i call the page then list of the comments is generated with the links to the parent comment only. But when i call the page/#comment-333 then only this parent comment with children is displayed. – Greg Skala Commented Oct 24, 2018 at 8:24
-
get_query_var()works on query strings only, and not URL hash like that. – Sally CJ Commented Oct 24, 2018 at 8:25 - would be possible to rewrite differently with the "#comments-" before ?? add_rewrite_rule('^question/#comments-([^/]*)/?',', 'index.php?page_id=77&question=$matches[1]','top'); – Greg Skala Commented Oct 24, 2018 at 8:28
1 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;
}
本文标签: rewrite rules problem with comments2345
版权声明:本文标题:rewrite rules problem with #comments-2345 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749236873a2337423.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


get_query_var()works on query strings only, and not URL hash like that. – Sally CJ Commented Oct 24, 2018 at 8:25