Saturday, July 27, 2013

How to Include Custom Post Types in Archive page (WordPress)

Archives page (archives.php) shows content of type 'post' not 'custom post', but you can modify archive file (archives.php file in your current template folder) to include custom post types. Add this filter to your functions.php file:

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' );


Disqus Comments