admin管理员组

文章数量:1296460

I want to create an author archive for only custom post type. This page will includes only custom posts by the author.

And url structure should be example/portfolio/author/author-name/

I don't want to include custom type to default author.php because my custom post type is in different language.

I want to create an author archive for only custom post type. This page will includes only custom posts by the author.

And url structure should be example/portfolio/author/author-name/

I don't want to include custom type to default author.php because my custom post type is in different language.

Share Improve this question asked May 2, 2016 at 7:15 akarimakarim 3052 gold badges5 silver badges15 bronze badges 1
  • Someone else posted an answer to this question that I found even better, because it just appends the custom post type as a query to the URL for the author, thus loading the default archive page for the custom post type. Take a look here. – tommycopeland Commented May 8, 2018 at 11:47
Add a comment  | 

1 Answer 1

Reset to default 3

According to this blogpost you just need to add the following code to your themes functions.php or in a plugin:

/* Add CPTs to author archives */
function custom_post_author_archive($query) {
    if ($query->is_author)
        $query->set( 'post_type', array('custom_type', 'post') );
    remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action('pre_get_posts', 'custom_post_author_archive'); 

本文标签: Author archive only for custom post type