Displaying Custom Post Types in a Custom Taxonomy Archive
The project I was working on today required a custom post type that included a custom taxonomy. Setting this up on the back end was simple. However, when I went to the front end, all the posts in the custom post type were missing from the custom taxonomy archive. Since it took me way too long to figure out the source of this issue, I’m going to document it here.
It all comes down to this poorly named setting:
When registering a post type, this setting determines whether or not your custom post type will show up in your site’s search results. However, it also has the unexpected side effect of determining whether or not your custom post type will show up on taxonomy archive pages. If you want to include your custom post type in custom taxonomy archives, exclude_from_search must be set to false:
'exclude_from_search' => false,
Note: If the “public” setting is set to “true” then the “exclude_from_search” setting can simply be removed.
Special thanks to Pieter Goosen for mentioning this issue in this Stack Exchange thread.
This issue is also mentioned in the “exclude_from_search” section of the old WordPress Codex page for registering custom post types.