How to display regular posts & custom post types that fall under a category using just the generic category template?

Take a look at the query_posts() function – your amigo for altering the main/default query. You want to call global $wp_query beforehand to alter the original query instead of replacing it.

Something like this should do the trick for you. Put the first four lines in your category.php right before the main loop begins:

// Modify the default loop, include custom post types
global $wp_query;
$args = array_merge( $wp_query->query, array( 'post_type' => 'any' ) );
query_posts( $args );

// The beginning of the loop looks like this:
while ( have_posts() ) : the_post();

If you want to be more selective in displaying your post types you can provide an array with the desired post types instead of generic 'post_type'=>'any':

$args = array_merge( $wp_query->query, array( 'post_type' => array('post','news','essays') ) );

And welcome back to the WordPress universe and WPSE community.
I’m sure the frustration will be gone soon 😉

Leave a Comment