Skip to content

Instantly share code, notes, and snippets.

@stephenscaff
Created August 21, 2015 00:59
Show Gist options
  • Select an option

  • Save stephenscaff/ca2d2fdff03671bdfd42 to your computer and use it in GitHub Desktop.

Select an option

Save stephenscaff/ca2d2fdff03671bdfd42 to your computer and use it in GitHub Desktop.
Add Custom Post Types to archive in Wordpress.
function namespace_add_custom_types( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
'post', 'nav_menu_item', 'your-custom-post-type-here'
));
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