Skip to content

Instantly share code, notes, and snippets.

@jcamp
Forked from barbwiredmedia/add_custom_types.php
Created July 7, 2018 10:47
Show Gist options
  • Save jcamp/c821e211e362e7c2ab7b3a6c1f4e8e95 to your computer and use it in GitHub Desktop.
Save jcamp/c821e211e362e7c2ab7b3a6c1f4e8e95 to your computer and use it in GitHub Desktop.
Wordpress_Make Archives.php Include Custom Post Types - Archives.php only shows content of type 'post', but you can alter it to include custom post types. http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/
//functions.php
function namespace_add_custom_types( $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', 'namespace_add_custom_types' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment