Add Custom Post Types to Author Archives

Author Archives exclude custom post types by default, this snippet adds them back.

By default, WordPress only includes ‘posts’ in the Author Archive. To fix this, you need to modify the pre_get_posts filter to accommodate for your missing post types.

function post_types_author_archives($query) {

	// Add ‘videos’ post type to author archives
	// Add your own Post types in single quotes before 'post'
	if ( $query->is_author ) {
		$query->set( 'post_type', array('videos','post') );
		// Remove the action after it’s run
		remove_action( 'pre_get_posts', 'post_types_author_archives' );
	}
}
add_action( 'pre_get_posts', 'post_types_author_archives' );

Questions