admin管理员组文章数量:1425803
I want to create my own url like this http://localhost/wptest/content/programs/trainings-conferences/
I have create my own plugin and use this code.
add_action('init','wpyog_add_rewrite_rules');
add_action('init','wpyog_add_rewrite_rules');
function wpyog_add_rewrite_rules(){
add_rewrite_rule('^content/([^/]*)/([^/]*)/?','index.php?content_category=$matches[1]content_slug=$matches[2]','top');
}
add_action('query_vars','wpyog_add_query_vars');
function wpyog_add_query_vars( $qvars ) {
$qvars[] = 'content_category';
$qvars[] = 'content_slug';
return $qvars;
}
add_action('template_redirect','wpyog_template_redirect');
function wpyog_template_redirect(){
if( get_query_var('content_slug') && get_query_var('content_category') )
{
include( WPYog_Ukraine_PATH.'templates/frontend_template.php' );
exit();
}
}
But its not working its shows 404 page. While I am using this url its works http://localhost/wptest/?category=programs&category_slug=trainings-conferences
I want to create my own url like this http://localhost/wptest/content/programs/trainings-conferences/
I have create my own plugin and use this code.
add_action('init','wpyog_add_rewrite_rules');
add_action('init','wpyog_add_rewrite_rules');
function wpyog_add_rewrite_rules(){
add_rewrite_rule('^content/([^/]*)/([^/]*)/?','index.php?content_category=$matches[1]content_slug=$matches[2]','top');
}
add_action('query_vars','wpyog_add_query_vars');
function wpyog_add_query_vars( $qvars ) {
$qvars[] = 'content_category';
$qvars[] = 'content_slug';
return $qvars;
}
add_action('template_redirect','wpyog_template_redirect');
function wpyog_template_redirect(){
if( get_query_var('content_slug') && get_query_var('content_category') )
{
include( WPYog_Ukraine_PATH.'templates/frontend_template.php' );
exit();
}
}
But its not working its shows 404 page. While I am using this url its works http://localhost/wptest/?category=programs&category_slug=trainings-conferences
Share Improve this question asked Jun 11, 2019 at 12:49 SudhirSudhir 1136 bronze badges 3- 1 Missing & in rewrite pattern. – birgire Commented Jun 11, 2019 at 12:53
- @birgire Can you please correct it in proper way – Sudhir Commented Jun 11, 2019 at 12:56
- also did you resave/flush the permalinks after changing the rewrite rules? – Tom J Nowell ♦ Commented Jun 11, 2019 at 13:08
1 Answer
Reset to default 1your rewrite patern miss a "&" between $matches[1]
& content_slug
function wpyog_add_rewrite_rules(){
add_rewrite_rule('^content/([^/]*)/([^/]*)/?','index.php?content_category=$matches[1]&content_slug=$matches[2]','top');
}
本文标签: plugin developmentHow to create custom dynamic url
版权声明:本文标题:plugin development - How to create custom dynamic url 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745414207a2657606.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论