Title: Template for custom post type
Last modified: February 13, 2018

---

# Template for custom post type

 *  Resolved [ModestUs](https://wordpress.org/support/users/modestus/)
 * (@modestus)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/template-for-custom-post-type-3/)
 * Hi there,
 * I’m trying to create a custom template for my new custom post type.
 * I’ve tried creating a single-[my-post-type].php, but for some reason that template
   does not get used. After some research I’ve discovered that my custom post type
   for some reason uses the default page.php – not single.php. Just for the fun,
   I tried creating a page-[my-post-type].php, but with no luck.
 * When I inspect the page in the browser I can see that the <body> tag gets a class
   of “type-attachment”.
 * I am mystified. Can anybody help?
 * Thanks 🙂
 * //Rasmus

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 3 months ago](https://wordpress.org/support/topic/template-for-custom-post-type-3/#post-9971021)
 * Some fun information for you.
 * Attachments are technically posts in a post type. This includes slugs. My bets
   are that you have an attachment that has the same name as the post type in question,
   and the attachment is getting interpreted first, as being the content being queried
   for.
 * Due to the attachment detail, the attachment-based template files would be picked
   up, but not something like page-[my-post-type].php and similar. I assume the 
   post type is more important than an attachment slug, so if I was in the situation,
   I’d end up locating the offending attachment and rename the post_name value in
   the db.
 *  Thread Starter [ModestUs](https://wordpress.org/support/users/modestus/)
 * (@modestus)
 * [8 years, 3 months ago](https://wordpress.org/support/topic/template-for-custom-post-type-3/#post-9972892)
 * Thanks, that was the answer. Turns out I had an attachment with the same title
   as the specific post. After changing that, everything works as it should.
 * But… How can you avoid this problem? If someone were to upload a new attachment
   and name it the same as an existing post, won’t the problem be back?
 *  Plugin Contributor [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * (@tw2113)
 * The BenchPresser
 * [8 years, 2 months ago](https://wordpress.org/support/topic/template-for-custom-post-type-3/#post-9973868)
 * Very likely that would return, at least for that post. I can’t say there’s any
   great way to prevent this type of thing, but from my experiences, it’s also been
   a very infrequent issue as well. I know CPTUI compares potentially saved slugs
   against existing pages and other post types, but we don’t have it set up to compare
   against the post_name value from the database. Given the amount of posts that
   can easily accumulate in the database, that’d get server intensive pretty quickly.
 * My take is that it’s an edge case situation that’s best left to when it happens
   to come up.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Template for custom post type’ is closed to new replies.

 * ![](https://ps.w.org/custom-post-type-ui/assets/icon-256x256.png?rev=2744389)
 * [Custom Post Type UI](https://wordpress.org/plugins/custom-post-type-ui/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/custom-post-type-ui/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/custom-post-type-ui/)
 * [Active Topics](https://wordpress.org/support/plugin/custom-post-type-ui/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/custom-post-type-ui/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/custom-post-type-ui/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Michael Beckwith](https://wordpress.org/support/users/tw2113/)
 * Last activity: [8 years, 2 months ago](https://wordpress.org/support/topic/template-for-custom-post-type-3/#post-9973868)
 * Status: resolved