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

Read More
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.

Related posts

1 comment

  1. 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');
    }
    

Comments are closed.