WordPress, WordPress development

Make Author.php Include Custom Post Types

Last updated on July 6th, 2021 by Adnan





I was going through a strange issue where Author page was not showing the posts which belongs to Custom Post Types. After Googling, I found this article which shows how to include Custom Post Types for archives.php

I got inspiration from above mentioned article snippet and wrote the following snippet to modify Author.php page to include Custom Post Types

function wpbrigade_author_custom_post_types( $query ) {
  if( is_author() && empty( $query->query_vars['suppress_filters'] ) ) {
    $query->set( 'post_type', array(
     'post', 'my-custom-post-type-here'
		));
	  return $query;
	}
}
add_filter( 'pre_get_posts', 'wpbrigade_author_custom_post_types' );

 

Share on




3 responses to “Make Author.php Include Custom Post Types”

  1. nartcan Avatar
    nartcan

    You should include the author check with category and tag:
    if( is_author() || is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) )

  2. Thiết kế Website chuyên nghiệp Avatar

    It working for me but it make proplem with ACF. It not display correctly !!!

  3. Rodolfo Avatar

    Awesome post!
    Any thoughts on how to exclude a specific Term from the query?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.