Skip to content

Instantly share code, notes, and snippets.

@jorpdesigns
Created July 14, 2021 10:34
Show Gist options
  • Save jorpdesigns/bdcd223b86e9e7e3e4e44e3c18bdf102 to your computer and use it in GitHub Desktop.
Save jorpdesigns/bdcd223b86e9e7e3e4e44e3c18bdf102 to your computer and use it in GitHub Desktop.
Snippet to add other custom post types to WordPress author archive
<?php
add_filter( 'pre_get_posts', 'add_post_types_to_archives' );
function add_post_types_to_archives( $query ) {
if ( is_admin() || ! $query->is_main_query() ) {
return;
}
if ( is_author() && empty( $query->query_vars['suppress_filters'] ) ) {
$cpts = array( 'page', 'podcasts' ); // Replace with your own custom post types
$query->set(
'post_type',
array_merge(
array( 'post' ),
$cpts
)
);
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment