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.

If I, for example, create a custom post type named 'tutorial', how do I get it to also show up in places like "Recent posts" , etc?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Hooking the following function with the pre_get_posts filter will add one or more CPTs to the regular archive pages:

function wpse94041_cpts_in_archives( $query ) {
    if( is_category() || is_tag() ) { // more conditional tags possible, if applicable
        $query->set( 'post_type', array(
            'post',
            'tutorial' // add as many CPTs to this array as you like
        ));
    }
    return $query;
}
add_filter( 'pre_get_posts', 'wpse94041_cpts_in_archives' );

Your theme's functions.php file would be a good fit for the above.

share|improve this answer
    
Thanks a lot for your answer. I put the script at the end of my theme's functions.php but sadly it didn't work. Would there be something more to configure? –  StCee Mar 31 '13 at 17:00
    
Worked after removin the if( is_category() || is_tag() ) conditional. Not sure if it is ok to skip that. –  StCee Mar 31 '13 at 17:40
    
If you remove the conditional, this will modify every query. Rather than removing it, I'd recommend modifying it to your needs. Use some other conditional tags instead, that are more suiting to your situation. –  Johannes Pille Mar 31 '13 at 18:37
    
Weirdly I found out that it only works as long as 'page' is in the array. Otherwise no document found would be returned. –  StCee Apr 1 '13 at 2:53
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.