WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

1) My site has posts, and 2 custom post types (news & essays) 2) They all share normal categories like sports & health (no custom taxanomy involved) 3) Using the generic category.php template, how do I make it so this template handles all categories while displaying all content falling under it regardless of content post type.

Or simply, I would like the generic category.php template to handle all category displays but should include custom post types as well.

This may be a stupid question but have returned to Wordpress after a long hiatus and am finding the default wordpress themes hard to understand to do this. Just confused and frustrated right now.

Please help

share|improve this question
up vote 5 down vote accepted

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

share|improve this answer
It worked! Thank you so much Maugly. Can't show enough appreciation ... twas so frustrating. Love ya... as a platonic admirer, of course :p – damx Aug 30 '11 at 7:18

At first I used Maugly's solution but then i found this one in wordpress codex :

add_action( 'pre_get_posts', 'add_my_custom_post_type' );
 * @param WP_Query $query
 * @return WP_Query
function add_my_custom_post_type( $query ) {
    if ($query->is_main_query()) 
        $query->set( 'post_type', array( 'post', 'page', 'any_custom_type' ) );
    return $query;

Hope it will help someone .. maybe it's not the cleanest but a little bit cleaner than Maugly's solution ..

share|improve this answer

► Here is my version of the @Kower's suggestion. Solves a couple of problems in admin.

add_action('pre_get_posts', 'add_my_custom_post_type');

 * @param WP_Query $query
 * @return WP_Query
function add_my_custom_post_type($query) {
        or $query->query['post_type'] === 'post'
        $query->set('post_type', array('post', 'my_custom_type'));
share|improve this answer
Also possible: $query->set('post_type', 'any'); – tivnet Mar 15 '13 at 3:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.