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

WordPress WordPress Theme Development Custom Post Type Templates in WordPress Coding Your Own Custom Post Type Templates

Loren Shumaker-Chupp
Loren Shumaker-Chupp
2,711 Points

New Custom Post Type Posts not publishing.

I have been having issues making posts in new custom post types publish to a page. Every time I try and add a post to a custom post type and try and preview it, it 404s. I've tried creating multiple new types in CPT UI and corresponding Advanced Custom Fields rules. Each time I create one and make a new post the posts 404.

I've successfully added CPT in the past. I went into an old site I'd done this tutorial with, updated all of the plugins and WordPress to the same version as the site I'm having problems with, and tried doing the same thing. To my surprise the issue is prevalent there as well. However if I create a new post to the previous CPT I had on the old site, the new posts do not 404.

I can not figure out what I'm missing.

Loren Shumaker-Chupp
Loren Shumaker-Chupp
2,711 Points

Additional information on what I've tried:

On the old site that has a working CPT: I copied all of the fields I had made in the working CPT and made a new one (with different field names and Post Type name) and it does not work. I created a single-posttypename.php file for it and copied it over from the working post type but posts on the new CPT still 404.

It must be an issue with the CPT UI that I'm setting up but even if I create settings identical to the old CPT that worked, it doesn't seem to help. However, I switched the new Custom Field's location rule so the PostType was equal to the old CPT and that CPT still works. But when I set the old Custom Field's location to the new CPT, posts on that new CPT still 404.

Colin Marshall
Colin Marshall
32,861 Points

Please provide your code for your single-customposttype.php so we can have a look.

Loren Shumaker-Chupp
Loren Shumaker-Chupp
2,711 Points

Here's the single-testtype.php file I'm using. Testtype is the Custom Post Type I set up that seems to be 404ing. I've realized this is occurring when I add a second CPT. Is there a hierarchy or something that I need to be applying when using more than one CPT?

pastebin

1 Answer

Colin Marshall
Colin Marshall
32,861 Points

Sounds like a permalinks issue. Try going to Settings -> Permalinks and change it to something else, like default, save it, and change it back to what it was originally.