Skip to content

Instantly share code, notes, and snippets.

@Clorith
Created August 4, 2013 22:30
Show Gist options
  • Save Clorith/6152213 to your computer and use it in GitHub Desktop.
Save Clorith/6152213 to your computer and use it in GitHub Desktop.
WordPress hook and function to display various posts and custom post types on author pages
/*
* Function for modifying the main query
*/
function modify_the_loop( $query ) {
// Check that this is the main query, not a secondary one, and trigger if it's the author page'
if ( $query->is_main_query() && $query->is_author() )
{
$query->set( 'post_type', array( 'post', 'page', 'CPT', 'CPT2' ) );
}
}
add_action( 'pre_get_posts', 'modify_the_loop' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment