Wordpress custom url writting not working

喜欢而已 提交于 2020-01-16 09:01:29

问题


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

How can I create frontend link. So that it can satisfied our re-write rule

来源:https://stackoverflow.com/questions/56544224/wordpress-custom-url-writting-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!