[resolved] Modifying Author Archive to include Custom Post Types and Pagination (4 posts)

  1. jimmiejo
    Posted 5 years ago #

    I'm having a bit of a problem with custom post types and author archives.

    By default, the author.php will return posts by the selected author. I'm working on a build that only uses custom post types, and need to show just these custom types on the author archive page.

    It's easy enough to query just a custom content type in that template:

    query_posts( 'post_type=products' ); if (have_posts())

    ...as found here: http://www.wpquestions.com/question/show/id/1862 -- but that results in broken pagination (domain.com/author/their-name/page/2/ returns the 404 page).

    And I've tried Michael's simple tip for paginating a wp_query = http://wordpress.org/support/topic/authorphp-post-problem#post-1233086, but that didn't do the trick either.

    Would really appreciate it if anyone could point me in the right direction for returning only specific custom content types on author archive pages, and have the pagination work.

  2. jimmiejo
    Posted 5 years ago #

    Found a function that seemed to do the trick:

    function custom_post_author_archive( &$query )
        if ( $query->is_author )
            $query->set( 'post_type', 'name-of-post-type-here' );
        remove_action( 'pre_get_posts', 'custom_post_author_archive' ); // run once!
    add_action( 'pre_get_posts', 'custom_post_author_archive' );

    Via http://wordpress.stackexchange.com/questions/11210/including-post-type-wiki-in-author-archives

  3. Pancho Perez
    Posted 4 years ago #

    Hi Jimmiejo,

    It works, but since I add this hack author.php only shows the authors which had write a CPT, but if the user only have normal posts don´t shows anything.

    Could be the rewrite rules? This is what I´m using:

    [Code moderated as per the Forum Rules. Please use the pastebin]

  4. hjbarraza
    Posted 4 years ago #


    You sir, are my hero of the day.
    Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic