Skip to content

Instantly share code, notes, and snippets.

@brycejacobson
Created April 24, 2014 14:32
Show Gist options
  • Save brycejacobson/11256777 to your computer and use it in GitHub Desktop.
Save brycejacobson/11256777 to your computer and use it in GitHub Desktop.
Add custom post types to archives in WordPress
<?php
// Add custom post types to archives
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$post_types = get_post_types( '', 'names' );
$query->set( 'post_type', $post_types);
return $query;
}
}
add_filter( 'pre_get_posts', 'namespace_add_custom_types');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment