Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jonathan Davies](https://secure.gravatar.com/avatar/b504818276133f2009c042e554ef1162?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jonathan Davies
2,162 PointsCustom Post Types & Tags.
So my problem is i have my regular posts, and project posts (custom posts). What i'm trying to do is pull posts from these two post types that share the same tag(s) and display them.
Also i'm not looking for a specific tag=12 or tag=apples, i'm looking for something more complex. Something that displays what ever tag I happen to click and display those posts.
Any help that doesn't involve a plugin would be appreciated.
3 Answers
![Jonathan Davies](https://secure.gravatar.com/avatar/b504818276133f2009c042e554ef1162?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jonathan Davies
2,162 PointsSo i fixed this with...
if ( ! function_exists( 'filter_tag' ) ) { function filter_tag($query) { if ($query->is_tag) { $query->set('post_type', array('post', 'portfolio')); }; return $query; }; } add_filter('pre_get_posts', 'filter_tag');
![John Locke](https://secure.gravatar.com/avatar/288f43b2e85b2451c08aa86f0e0453ad?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
John Locke
15,479 PointsHow many tags do you expect to end up with? And are there specific filters you want to apply besides the tag links?
The simple way would be alter the Tag template to query for post-type = Post and your Custom Post Types. A less elegant way would be construct a specific page with a specific template for each tag that does the same thing (Query the tag in post-type Post and Custom Post Type).
![Jonathan Davies](https://secure.gravatar.com/avatar/b504818276133f2009c042e554ef1162?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jonathan Davies
2,162 PointsWell I made the tag.php and it does indeed get the posts for me, but it wont get posts from the custom post type for some reason.