简体   繁体   中英

Wordpress Rewriting Rules

I have a Wordpress Multisite installation and I add custom post type named course in blog 1 and then I select the other blogs where I want see it.

In other blogs add a page that I use like single course template.

The url of this page is

http://example.com/blogName/course/?course-name=lorem-ipsum&course-id=xx

I would like to have a url like this

http://example.com/blogName/course/lorem-ipsum

and i would like to get the course-id parameter in template page.

I tried to use add_rewrite_rule but i'm not able to do what i want.

add_filter('query_vars', 'my_query_vars', 10, 1);
function my_query_vars($vars) {
    $vars[] = 'course-name';
    return $vars;
}

add_action( 'init', 'init_custom_rewrite' );
function init_custom_rewrite() {
    add_rewrite_rule(
    '^course/([^/]*)/?','index.php?course-name=$matches[1]','top');
}

How can I do this? I need to add something to .htaccess?

Once you've executed the above hooks, find a way to call the flush rewrite function which will update the rewrite cache so it should start working.

flush_rewrite_rules( true );

Documentation for this function can be found on the developer docs site .

You can indirectly call that function too by just saving the Permalinks settings in the dashboard by going to Settings > Permalinks .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM