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
  • 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; 
}

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; 
}

本文标签: rewrite rules problem with comments2345