By default, author (and other) archives in WordPress display only posts but not Custom Post Type entries.

If you are looking to include items of one or most CPTs in your author archive pages, pre_get_posts comes to the rescue!

Add this code in your child theme’s functions.php or as a Code Snippet:

add_action( 'pre_get_posts', 'wpdd_add_cpt_author_archives' );
function wpdd_add_cpt_author_archives( $query ) {
	// if this is not the main query or we are in the backend or if the page being viewed is not the author archive, abort.
	if ( ! $query->is_main_query() || is_admin() || ! is_author() ) return;

	$query->set( 'post_type', array( 'post', 'portfolio' ) ); // replace portfolio with your CPT slug.
}

Replace portfolio with the slug of your desired CPT.

Ensure that you are in PHP mode i.e, there’s an opening PHP tag before the code.

For Oxygen users: Make sure that Easy Posts or Repeater’s query type is set to default inside the Template that applies to all/author archives.

Need help implementing a tutorial in your site or want to hire me for custom work?

HIRE ME

Find the article helpful and wish to donate?

DONATE

Comments

You need to be logged in to view and post comments.
Not a member yet? Join here.
magnifiercross
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram
%d bloggers like this: