最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

rewrite rules problem with #comments-2345

matteradmin11PV0评论

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
 |  Show 6 more comments

1 Answer 1

Reset to default 0

Try adding a query var

add_filter('query_vars', 'foo_my_query_vars'); 
function foo_my_query_vars($vars){ 
  $vars[] = 'question'; return $vars; 
}

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far