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?


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(
            '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.

| 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

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.