Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a custom post type with a custom URL structure so it works like:

http://domain.com/custom-post-type/post1
http://domain.com/custom-post-type/post2
http://domain.com/custom-post-type/post3
etc.

Now I have multiple authors of these posts, so I want to enable an "Author Archive" for only these custom post types at urls like this:

http://domain.com/custom-post-type/authorname1
http://domain.com/custom-post-type/authorname2
http://domain.com/custom-post-type/authorname3

Is this possible? Any ideas?

Thanks!

UPDATE: @Milo points out (I believe correctly) that "WordPress wouldn't be able to discern what is a post title and what is an author name," so given that, how would I get URLs like http://domain.com/custom-post-type/author/authorname1 ? Thanks!

share|improve this question
    
WordPress wouldn't be able to discern what is a post title and what is an author name. It would work if you gave it a unique prefix, like: http://domain.com/custom-post-type/author/authorname1 –  Milo Jan 25 '13 at 3:49
    
Understood. How do you do that? (I'll modify the question ... ) –  GavinR Jan 25 '13 at 4:15
    
See my answer below. –  Milo Jan 25 '13 at 5:36

1 Answer 1

up vote 2 down vote accepted

Change custom-post-type in the following to the name of your CPT, both the slug and post_type= in the query vars. Visit your Permalinks Settings page to flush rewrite rules. You could also put this in a plugin and flush rules on plugin activation.

function wpa83047_author_rewrite_rule(){
    add_rewrite_rule(
        '^custom-post-type/author/([^/]+)/?$',
        'index.php?author_name=$matches[1]&post_type=custom-post-type',
        'top'
    );
}
add_action( 'init', 'wpa83047_author_rewrite_rule' );
share|improve this answer
    
That works great! THANKS! –  GavinR Jan 26 '13 at 21:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.