Skip to content

Instantly share code, notes, and snippets.

@markdeafmcguire
Last active July 21, 2020 17:04
Show Gist options
  • Save markdeafmcguire/54d48d1b87acd3ec6d30a317ae3ec939 to your computer and use it in GitHub Desktop.
Save markdeafmcguire/54d48d1b87acd3ec6d30a317ae3ec939 to your computer and use it in GitHub Desktop.
Add filter to check for tag 'cpacc' before running query to include CPT 'drafts' in archive loop
// ADD FILTER TO SHOW CPT IN TAG ARCHIVES
add_filter( 'pre_get_posts', 'tag_archives_show_cpts' );
function tag_archives_show_cpts( $query ) {
if( is_tag('') &&
empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array( 'post', 'nav_menu_item', 'drafts'));
return $query;
}
}
// Adapted From Source: https://wpbeaches.com/show-custom-post-types-category-archive-page/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment