I want to have a way of displaying a custom post archive for a particular author. I'm able to display custom posts for a category but not just the custom posts for a author. I already have a separate author page template displaying all the posts they have written divided by post type. I'm querying this using :

    'post_type' => 'custom_post_name', 
while (have_posts()) : the_post();

Essentially I want a number of author templates pages for every author.

  • It isn't clear what you want. You have an author template but you also want several other author templates per author? What do these templates do? How are they different from the author template you have? – s_ha_dum Dec 17 '12 at 14:22
  • Seems like Josh want one author template for each post type. is that Josh? – M-R Dec 17 '12 at 14:41
  • M-R that is it. A general author template(which is done) and one author template per post type. – Josh Dec 17 '12 at 15:02

Three steps need to be followed to accomplish it.

1. Add rewrite rules

add_action('generate_rewrite_rules', 'author_cpt_add_rewrite_rules');
function author_cpt_add_rewrite_rules( $wp_rewrite ) 
  $new_rules = array( 
     'author/(.+)/(.+)' => 'index.php?author='.$wp_rewrite->preg_index(1) .
                            '&post_type=' .$wp_rewrite->preg_index(2) );

  //​ Add the new rewrite rule into the top of the global rules array
  $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;

2. Redirect to specific templates

function author_cpt_template_redirect() {
    global $wp_query;
    // check for the target request
    if (!empty($wp_query->query_vars['author']) && !empty($wp_query->query_vars['post_type'])) {
        // turn off 404 error
        $wp_query->is_404 = false;

        // include if template is available
        else if(file_exists('author.php'))



3. Query posts to populate the page or template

add_action('template_redirect', 'author_cpt_template_redirect', 1);
function query_author_cpts( $query ) {
    // check for the target request
    if (!empty($query->query_vars['author']) && !empty($query->query_vars['post_type'])) 
        // query posts accordingly
        query_posts( array( 
                        'post_type' => $query->query_vars['post_type'],
                        'author_name' => $query->query_vars['author'],
                        'paged' => get_query_var( 'paged' ) )
add_action( 'wp', 'query_author_cpts' );
| improve this answer | |
  • Thanks M-R. I have added the code and create an author page for one of the custom post types author-custom_post.php but when I go to ?author=name&post_type=custom_post it keeps bringing back the default author.php page. Is there something that I'm doing wrong? – Josh Dec 18 '12 at 11:10
  • are not you using %postname% permalink? For %postname% permalink, http://example.com/author/admin/post is working.. I did not tested with default permalink. – M-R Dec 18 '12 at 11:26
  • I get a page not found with that path. – Josh Dec 18 '12 at 11:29
  • you flushed the permalink? Admin->Setting->Permalink->save – M-R Dec 18 '12 at 11:36
  • that's working but still reverting to author.php rather than author-custom_post_type.php – Josh Dec 18 '12 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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