The 404 page happens because the permalinks haven’t been updated after you inserted the code.
You can do either of these things:
-
Manually update the permalinks after you add the new custom post type (needs to be done only once)
-
Include the custom post type file in the theme setup function and follow with a
flush_rewrite_rules( );
, then reactivate the theme. reference here
Edit: Please don’t include the code flush_rewrite_rules( );
in your custom post php file since the function is very expensive to run everytime the wordpress engine loads.