Custom Post Types and the 404 Conundrum
Have you ever built out some custom post types(CPT), and when trying to get to the single post for the CPT you run into the dreaded 404 error?
Yea, me too. And it’s not fun.
Luckily the fix is usually pretty super simple. This is of course assuming that all of your loops and queries are properly set up and it’s not a coding issue. Before doing anything else, your first stop should be your error logs to see if it is indeed a coding problem.
First, you can’t have your page template named the same as your CPT. So if you created a Books CTP (remember, no caps when registering!!), if you created a special page template if can be named anything but page-books.php. That gives WordPress and headache. And when WordPress gets headaches, you’re in for some migraines.
If this is the case, rename it to something else (just remember to reset the Template on your Page since it will be reset to Default).
Even if you don’t have to do the first step (but especially if you had to do the first step) go into your Permalinks and reset them. This will remap everything.
Usually, these two steps will do the trick! Nicely done.
If not, you may have a hierarchy problem and your templating isn’t being called the way you think it is. A neat little visual to help you figure this out can be found at https://wphierarchy.com/