wordpress snippets last updated   : April 22, 2014
we now have 631 snippets

Add custom post types to archives page

wordpress snippet

Adding this snippet to the functions.php of your wordpress theme will let you add custom post types to archives page.

snippet :  PHPcopy
function add_custom_types_archive( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
 'post', 'your-custom-post-type-here'
            ));
      return $query;
    }
}
add_filter( 'pre_get_posts', 'add_custom_types_archive' );
source →
  • Zbudnick

    Gave this a try – I’m using Custom Post Types UI with Design Chemical Mega Menu in WP 3.2.1 – the CPT’s do get displayed, but:
    -some images do not display on welcome page
    -menu disappears/goes blank
    -all CPTs get included in recent posts
      
    Any thoughts on how to make this work…?
     
    Thanks in advance

    • http://twitter.com/behemothdan BehemothDan

      Add this as an additional post type –  ’nav_menu_item’

jqsnipp.com | we just launched jquery snippets website