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
1 Answer
Reset to default 3According 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
版权声明:本文标题:Author archive only for custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741638545a2389778.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论