Skip to content

Instantly share code, notes, and snippets.

@adambradford
Last active March 30, 2018 15:34
Show Gist options
  • Save adambradford/8e2fea8e63502c7f25410eefddd0642a to your computer and use it in GitHub Desktop.
Save adambradford/8e2fea8e63502c7f25410eefddd0642a to your computer and use it in GitHub Desktop.
Display Custom Post Type in WordPress Author Archive
<?php
//* Add this to your functions.php file. Do NOT include the opening php tag
// Display Custom Post Type in Author Archive
function post_types_author_archives($query) {
if ($query->is_author)
// Allow 'my_custom_post_type' CPT and the default 'posts' to display in author's archive
$query->set( 'post_type', array('my_custom_post_type', 'posts') );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action('pre_get_posts', 'post_types_author_archives');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment