X

Add Custom Post Types to Archives Page

Snippets by IsItWP

Do you want to add custom post type to archives page? By adding the following code to the functions.php file of your WordPress theme, you add custom post types to archives page.

function add_custom_types_archive( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {
$query->set( 'post_type', array(
 'post', 'your-custom-post-type-here'
            ));
      return $query;
    }
}
add_filter( 'pre_get_posts', 'add_custom_types_archive' );

We hope this code helped you add custom post types to archives page. You may also want to check out our guide on how to modify custom post types in WordPress.

Comments  Leave a Reply

  1. Gave this a try – I’m using Custom Post Types UI with Design Chemical Mega Menu in WP 3.2.1 – the CPT’s do get displayed, but:
    -some images do not display on welcome page
    -menu disappears/goes blank
    -all CPTs get included in recent posts
      
    Any thoughts on how to make this work…?
     
    Thanks in advance

    1. Add this as an additional post type –  ‘nav_menu_item’

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!