I have custom post types using the default categories

'taxonomies' => array('category')

how do I get the custom post types to appear when I click on the category link? Do I need to edit archive.php to pull them in?

or if I have a category template? Is it a get_template request?


You can use the following code in your category archive template file.

if (is_category()) {
    global $query_string;
    $post_type = get_query_var('post_type');
    if ( !$post_type ) { // if no post type is already defined
        parse_str( $query_string, $args );
        $args['post_type'] = array( 'post', 'you-custom-post-type-here' );
        query_posts( $args );

You can also use the above code in any action that gets run just before the main loop.

| improve this answer | |
  • oh ok, this seems to work as well (in functions.php) - any idea which is the best way to do it? function my_get_posts( $query ) { if ( is_home() || is_category() || is_archive() && false == $query->query_vars['suppress_filters'] ) $query->set( 'post_type', array( 'post', 'quotes' ) ); return $query; } – david arthur Jun 10 '11 at 20:19
  • I can't seem to get your code to work - do I just change the "you-custom-post-type-here" bit – david arthur Jun 10 '11 at 20:25
  • Your method is more appropriate if you don't want to modify the template file, but if you are good with modifying the template file then you can use mine. But your code also adds the custom post to all other type of archives include home page and daily monthly archives. – Hameedullah Khan Jun 10 '11 at 21:40
  • @david arthur If this answer is correct, you should mark it as "accepted". – Chip Bennett Aug 11 '11 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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