Show Custom Post Type Archive by Author
-
Hi
I’m building a theme and I’m trying to have it so that when a user clicks on the author name it only shows the custom post type for that author, and if the user is on the blog page and clicks and author name it only shows the blog posts by that author.
I’ve come across this piece of code:
function wpse107459_add_cpt_author( $query ) { if ( !is_admin() && $query->is_author() && $query->is_main_query() ) { $query->set( 'post_type', array('post', 'YOUR_CUSTOM_POST_TYPE' ) ); } } add_action( 'pre_get_posts', 'wpse107459_add_cpt_author' );
This almost solves the problem, but what this does is combine the blog posts and custom post types together. I would like it so the CPTs and blog post remain separate. If I delete the ‘post’ parameter on the 3rd line, this removes blog posts from the CPT archive when I click the author name, but it also removes them when I click the author name under the blog page.
What I need is some type of function called
is_post('custom-post-type-name')
that I can use in a piece of conditional logic, but I can’t find anything like this in the codex?I’d be happy to have any solution either in functions.php or in the author.php file.
Any help would be great.
Paul
- The topic ‘Show Custom Post Type Archive by Author’ is closed to new replies.