简体   繁体   中英

rewrite url in wordpress custom post type

I am trying to rewrite URL in my custom post type. This is the existing URL I am able to access:

http://domainname.com/new/projects/s-test-uco-10/

But I want to access the URL like this

http://www.domainname.com/new/projects/mail/s-test-uco-10/

Below is my code:

add_action('init', 'add_my_rule');
function add_my_rule()
{
 global $wp;
 $wp->add_query_var('args');
 add_rewrite_rule('^projects\/mail.*$','index.php?projects','top');
}

s-test-uco-10 is the post name, I want to pass this name dynamically.

please try below code .. hope it will help you

function add_my_rule()
 {
global $wp;
$wp->add_query_var('args');
add_rewrite_rule('^projects\/mail/([^/]+)$','index.php?project=$matches[1]','top');
}

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