admin管理员组文章数量:1025316
My target:
- Create a page template in theme (page-expert.php) following the guide Page Templates.
- Create a blank page with the template.
- The above page will show the profile information for certain users (by custom role 'expert' created by add roles).
- The default Wordpress link for a profile is http://mysite/author/expert-name. But I want the link http://mysite/writer/expert/[expert-nickname] should show the profile for user roles 'expert' user expert-nickname
It is more or less an implementation of add_rewrite_rule.
What I did:
Template file, role and page (page_id=211, slug=http://[mysite]/writer/expert) is created accordingly.
Redirection managed (through class myExpert initiation in function.php) and permalink settings updated:
class myExpert extends myWriters{
public function __construct(
add_filter('init', array($this, 'set_expert_link_base'));
add_filter("expert_link", array($this, 'fix_expert_link')); //For now, this changes the link of all author profiles. I'll look into it later.
}
function set_expert_link_base()
{
add_rewrite_tag('%expert%', '([^&]+)', 'expert=');
add_rewrite_rule('^expert/([^/]*)?','index.php?page_id=211&expert=$matches[1]','top');
}
function fix_expert_link($link)
{
if($link){
return str_replace("author","expert",$link);
}
}
}
Problem:
When calling http://mysite/writer/expert/[expert-nickname], the redirection to the page is taking place, but the get variable is not getting processed in page-expert.php. The following do not contain any index 'expert'. (Global $wp_query and $wp)
$wp->query_vars
$_REQUEST
$wp_query->query_vars
$exp_slug= get_query_var('expert');
ia blank
add_filter('request', array($this, show_req_vars()));
function show_req_vars($vars)
{
print_r($vars);
return $vars;
}
Outputs:
Array ( [page_id] => 211 )
What am I doing wrong/missing?
My target:
- Create a page template in theme (page-expert.php) following the guide Page Templates.
- Create a blank page with the template.
- The above page will show the profile information for certain users (by custom role 'expert' created by add roles).
- The default Wordpress link for a profile is http://mysite/author/expert-name. But I want the link http://mysite/writer/expert/[expert-nickname] should show the profile for user roles 'expert' user expert-nickname
It is more or less an implementation of add_rewrite_rule.
What I did:
Template file, role and page (page_id=211, slug=http://[mysite]/writer/expert) is created accordingly.
Redirection managed (through class myExpert initiation in function.php) and permalink settings updated:
class myExpert extends myWriters{
public function __construct(
add_filter('init', array($this, 'set_expert_link_base'));
add_filter("expert_link", array($this, 'fix_expert_link')); //For now, this changes the link of all author profiles. I'll look into it later.
}
function set_expert_link_base()
{
add_rewrite_tag('%expert%', '([^&]+)', 'expert=');
add_rewrite_rule('^expert/([^/]*)?','index.php?page_id=211&expert=$matches[1]','top');
}
function fix_expert_link($link)
{
if($link){
return str_replace("author","expert",$link);
}
}
}
Problem:
When calling http://mysite/writer/expert/[expert-nickname], the redirection to the page is taking place, but the get variable is not getting processed in page-expert.php. The following do not contain any index 'expert'. (Global $wp_query and $wp)
$wp->query_vars
$_REQUEST
$wp_query->query_vars
$exp_slug= get_query_var('expert');
ia blank
add_filter('request', array($this, show_req_vars()));
function show_req_vars($vars)
{
print_r($vars);
return $vars;
}
Outputs:
Array ( [page_id] => 211 )
What am I doing wrong/missing?
Share Improve this question edited Apr 7, 2019 at 8:11 sariDon asked Apr 7, 2019 at 7:58 sariDonsariDon 2651 gold badge2 silver badges18 bronze badges1 Answer
Reset to default 1Remove $query
parameter from add_rewrite_tag
. Your rewrite tag registration will look like this: add_rewrite_tag('%expert%', '([^&]+)');
.
The phrase in the rewrite rule may be '^expert/([^/]+)/?'
, but it was not the reason for the problem.
My target:
- Create a page template in theme (page-expert.php) following the guide Page Templates.
- Create a blank page with the template.
- The above page will show the profile information for certain users (by custom role 'expert' created by add roles).
- The default Wordpress link for a profile is http://mysite/author/expert-name. But I want the link http://mysite/writer/expert/[expert-nickname] should show the profile for user roles 'expert' user expert-nickname
It is more or less an implementation of add_rewrite_rule.
What I did:
Template file, role and page (page_id=211, slug=http://[mysite]/writer/expert) is created accordingly.
Redirection managed (through class myExpert initiation in function.php) and permalink settings updated:
class myExpert extends myWriters{
public function __construct(
add_filter('init', array($this, 'set_expert_link_base'));
add_filter("expert_link", array($this, 'fix_expert_link')); //For now, this changes the link of all author profiles. I'll look into it later.
}
function set_expert_link_base()
{
add_rewrite_tag('%expert%', '([^&]+)', 'expert=');
add_rewrite_rule('^expert/([^/]*)?','index.php?page_id=211&expert=$matches[1]','top');
}
function fix_expert_link($link)
{
if($link){
return str_replace("author","expert",$link);
}
}
}
Problem:
When calling http://mysite/writer/expert/[expert-nickname], the redirection to the page is taking place, but the get variable is not getting processed in page-expert.php. The following do not contain any index 'expert'. (Global $wp_query and $wp)
$wp->query_vars
$_REQUEST
$wp_query->query_vars
$exp_slug= get_query_var('expert');
ia blank
add_filter('request', array($this, show_req_vars()));
function show_req_vars($vars)
{
print_r($vars);
return $vars;
}
Outputs:
Array ( [page_id] => 211 )
What am I doing wrong/missing?
My target:
- Create a page template in theme (page-expert.php) following the guide Page Templates.
- Create a blank page with the template.
- The above page will show the profile information for certain users (by custom role 'expert' created by add roles).
- The default Wordpress link for a profile is http://mysite/author/expert-name. But I want the link http://mysite/writer/expert/[expert-nickname] should show the profile for user roles 'expert' user expert-nickname
It is more or less an implementation of add_rewrite_rule.
What I did:
Template file, role and page (page_id=211, slug=http://[mysite]/writer/expert) is created accordingly.
Redirection managed (through class myExpert initiation in function.php) and permalink settings updated:
class myExpert extends myWriters{
public function __construct(
add_filter('init', array($this, 'set_expert_link_base'));
add_filter("expert_link", array($this, 'fix_expert_link')); //For now, this changes the link of all author profiles. I'll look into it later.
}
function set_expert_link_base()
{
add_rewrite_tag('%expert%', '([^&]+)', 'expert=');
add_rewrite_rule('^expert/([^/]*)?','index.php?page_id=211&expert=$matches[1]','top');
}
function fix_expert_link($link)
{
if($link){
return str_replace("author","expert",$link);
}
}
}
Problem:
When calling http://mysite/writer/expert/[expert-nickname], the redirection to the page is taking place, but the get variable is not getting processed in page-expert.php. The following do not contain any index 'expert'. (Global $wp_query and $wp)
$wp->query_vars
$_REQUEST
$wp_query->query_vars
$exp_slug= get_query_var('expert');
ia blank
add_filter('request', array($this, show_req_vars()));
function show_req_vars($vars)
{
print_r($vars);
return $vars;
}
Outputs:
Array ( [page_id] => 211 )
What am I doing wrong/missing?
Share Improve this question edited Apr 7, 2019 at 8:11 sariDon asked Apr 7, 2019 at 7:58 sariDonsariDon 2651 gold badge2 silver badges18 bronze badges1 Answer
Reset to default 1Remove $query
parameter from add_rewrite_tag
. Your rewrite tag registration will look like this: add_rewrite_tag('%expert%', '([^&]+)');
.
The phrase in the rewrite rule may be '^expert/([^/]+)/?'
, but it was not the reason for the problem.
版权声明:本文标题:user roles - Wordpress add_rewrite_rule redirection match GET variable not passing through to custom template 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745618693a2159445.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论