Custom Post Type Archive Pages – WordPress

Need to show your custom post types on your category archive pages?

Add this to your functions.php file:

add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
  if(is_category() || is_tag()) {
    $post_type = get_query_var('post_type');
	if($post_type)
	    $post_type = $post_type;
	else
	    $post_type = array('post','cpt'); // replace cpt to your custom post type
    $query->set('post_type',$post_type);
	return $query;
    }
}

Now change the variable ‘cpt’ to the registered name of your custom post type, and voila!

A big thanks to parandroid over at http://wordpress.org/support/topic/custom-post-type-tagscategories-archive-page?replies=16 for this one.

Tags: , , , , ,

WordPress SEO: 10 tips for better search rankings

FREE E-book. Learn the basics of WordPress SEO and how to improve the key metrics
  • We won't sell your address to anyone. We hate spam too.
View my portfolio Get in touch

Leave a Reply