Add Custom Post Types to Tags and Categories in WordPress

WordPress gives you the ability to add custom post types and taxonomies easily with some simple code in your functions.php file, or through the use of a plugin like CustomPress. That means, you can quickly turn your WordPress site into a fairly well-featured CMS.

The only problem is, out of the box, WordPress does not automatically take your newly created custom post types and add them to the archive pages for existing taxonomies ‘categories’ or ‘tags.’

That means, if you created a custom post type called “movies” and used the native WordPress taxonomy “category” to categorize and order that custom post type, simply navigating to the archive for that category will not show your custom post type in the list of posts for that archive.

For example, you created a movie review site and used standard WordPress categories and tags with that custom post type so you could relate those reviews to your other posts or pages. Let’s say you decided to use a category of “drama.” Navigating to the category archive for drama, namely will not show the custom post type you just added – even though you selected the drama category.

This is frustrating for those who go through the trouble to add plan out a custom post type, taxonomies, add the content and then find out it doesn’t display correctly.

Some would call this a bug, but the developers at WordPress maintain that sorting archives is for normal post types for which WordPress was created, and adding in that functionality for custom post types requires some custom code. And indeed it does.

So, if you’d like your custom post types to show up in archive listings for your site’s standard tags and categories you can add the following code to your functions.php file:

function add_custom_types_to_tax( $query ) {
if( is_category() || is_tag() && empty( $query->query_vars['suppress_filters'] ) ) {

// Get all your post types
$post_types = get_post_types();

$query->set( 'post_type', $post_types );
return $query;
add_filter( 'pre_get_posts', 'add_custom_types_to_tax' );

If you’d like to add only specific post types to listings of tags and categories you can replace the line:

$post_types = get_post_types();


$post_types = array( 'post', 'your_custom_type' );

If you’d like to read more about the difference between custom post types, custom fields, and custom taxonomies you will be interested in this series of posts right here on

15 Responses

    Shaun Pollitt

    Craig, I’m really new to custom post types and while I make a little progress I keep ending back up where I started, which is looking for a good solution for posting press releases. I’d like to create a custom post type which includes the standard fields and also allows me to attach an image file and a PDF.

    I’ve tried using a lot of different plug-ins and tried writing my own code but nothing is working out for me. The ACF plug-in gets me close but I’m not sure how to call my single-press_release.php template. I’ve been working on this for over two days without any success.


      It can be kind of confusing if you’re just starting with CPTs, but I’d be happy to help if I can.
      Why don’t you post a link to your site, and I’ll see if I can work something up simultaneously on a test site and see if we can get it working together.


    Great post, Craig– As huriara says, I’ve been searching for hours for a solution, and this was it! =)

    One problem, though. The theme that our company is using has a shortcode to display recent posts on the homepage. But when I use my new CPT “blog” in the settings, I get nothing. Here’s the shortcode:

    [blog_posts count=”4″ post_category=”blog” title=”From the Blog” link_text=”Read More” character_count=”115″ layout=”four_col_small” style=”modern”]

    When I view the category for that post, your code allows those posts to be displayed, but something’s not registering with the short code. See below:
    Scroll to the bottom to see the From the Blog heading and no posts below. Going to:
    you can see that the CPT and category of Blog is definitely working.

    Any ideas? Am I best to contact the developer?

    I’m a bit of a novice when it comes to messing with the depths of WP code and CPT’s.



      Craig Grella


      it’s likely the developer of the theme created the functions for those shortcodes and baked them right into your theme. It’s also possible they work with a specific post type – probably just the standard posts.

      Aside from that, I’m a little confused from your message. It sounds like you created a custom pot type called “Blog”, which, if that’s true, probably isn’t a great idea. It will just cause too much confusion down the road.

      Your site should already include posting functionality, and you can create just a category “blog” you don’t need a new post type for that.

      If you want to create another area of your site for other articles, you might consider creating a custom post type called “articles” or better yet, try to be more descriptive with it.


    I have been insanely trying to find a way for this to work all other methods adding categories to both posts and custom posts but did not list both together. Now it finally lists them on the category. But when I call a page with all the posts from that category, all I get is every normal post.

    Can you please help me.


      For anyone else who has this problem, simply replace;

      $post_types = get_post_types();


      $post_types = array( ‘nav_menu_item’,’your_custom_type’, ‘news’ );


    You have no idea how you’ve helped me! Thanks! I spend a couple of hours trying to solve this problem :)


    There is an error in the code, causing all kinds of problems.

    It’s in this line:

    if( is_category() || is_tag() && empty( $query->query_vars[‘suppress_filters’] ) ) {

    The thing is that this is ambiguous between the || and &&. It would work for only tags, and if I switched the order of is_category() and is_tag(), it only worked for categories.
    I solved it by writing it like this:

    if( (is_category() || is_tag()) && empty( $query->query_vars[‘suppress_filters’] ) ) {

    Now it works for both tags and category pages.
    I also added && $query->is_main_query(), to make sure it didn’t affect other queries on the page.

    The end result is for that first line of the function is:

    if (
    ( is_tag() || is_category() )
    && $query->is_main_query()
    && empty( $query->query_vars[‘suppress_filters’] )
    ) {

    Hope this helps.


    Hi, this is so wonderful, I’ve been searching for this for DAYS now! I could almost kiss you! Except for one big issue I’m running into….. everything works great, and I now have a Category landing page that displays all the latest posts for a particular category, regardless of whether they are an original post or a custom-post type. But my permalinks are all different. So, example, we have a blog that is a category called /bwob/ with subcategory navigation, as well as a custom post type for that particular blog called /business-without-borders/ who shares the same subcategories as the “bwob” category. (unfortunately this was done before my time, so the addition of the custom post type for that blog was done later in the process to supposedly make putting in new “blog type” posts easier”), so we have some blog postings in the old standard default WP Category way, and then the new ones are using this custom post type and then put in the bwob subcategories, ….. however…. I need to change the permalinks for the ones that are the custom post types. I now have a mix of different permalinks going down my page as follows, and I’m actually getting duplicates of them:

    And, what’s worse is they wind up with different information on the different links. The one under the general blog category /bwob/ is able to pull up and display information such as author, but the one from from the custom post type url – /blog/ is pulling up the author as admin, and not the correct author at all. Unless they are duplicates? Please help me, I’m in dire straits here, I’ve been working on this for days and our client is going to hang us. :-( I just went ahead and bought a month’s subscription to your site. Any help would be so very appreciated!

    Thank you!


    Craig, you are hero status today! I made an account just so I could say that… That’s how grateful I am for this post! Thank you so much for sharing!! :)


    The solution presented here causes problem in the admin panel. You cannot filter posts with category. When you filter first time, it’s ok, but when you want to jump in the filter from one category to another, there is an error.

Comments are closed.