Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

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.

share|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
    
thanks Hameedullah –  david arthur Jun 12 '11 at 22:03
    
@david arthur If this answer is correct, you should mark it as "accepted". –  Chip Bennett Aug 11 '11 at 14:22
add comment

Your Answer

 
discard

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.