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.
Related Posts:
- Setting a custom sub-path for blog without using pages?
- Add Content to Page without shortcodes
- Loading custom page template via plugin
- How to quickly switch custom post type singular template?
- Create second custom 404 page for selected post type
- is_page_template not working as expected
- Help with CPT template pagination
- Create Template for Custom Post Type same like for Page
- Filter widget outputs
- How to get the current category with custom posts
- Custom permalink structure for remote content pages
- How can I allow users to edit text that will be displayed on a custom post type archive page?
- A certain theme is forcing it’s singular post layout
- Question on templates
- Custom post type option page template
- How can I load Template file from wordpress plugin
- How can I find out what template is my custom post type using?
- Loading a template for a URL pattern
- Custom Homepage As Single Page or Custom Post Type?
- Using custom post types within a section of a template
- Custom Post Type Template Based on Page Slug?
- using a template for more then 1 page
- Can I assign a template to a custom post type?
- What is singular.php?
- Searching multiple custom post types and pages
- Page Template as Custom Post Type Archive
- Taxonomy, Terms, and Template Files
- Using Templates with Custom Post Type UI
- Get page by template?
- Custom Post Type Archive URL takes over page URL
- Custom templates for posts like for pages: page-{id} vs single-{id}
- Posts in Multiple Columns and Rows with one single loop
- Display different gutenberg template from selected post attributes
- WordPress custom post type Single.php?
- Clean URL permalink for custom post type
- where can I see my custom post type archive template?
- Trying to manage templates on a blog with lots of custom taxonomies
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- Pagination Issue: Custom Post Type In Index
- Control Custom Post Type template from a plugin
- Detect if 1st, 2nd or 3rd level custom page?
- Hyphens instead of Underscores in Post-type Archive Template Filenames when Post-type handle contains underscore
- Can I make WordPress use a custom template for a child page
- How to load a template without it being assigned to a page/post?
- Custom Post Type with Templates using Meta Boxes?
- Posts are duplicating on wp_post_update
- Custom page sidebar using Template dropdown box
- Custom taxonomy and custom post type – wrong permalinks and template
- Can I override a CPT template on a per post basis with Gutenberg block editor?
- How to render a custom post type template with custom fields using shortcode
- A case for Hierarchical Custom Posts
- Custom taxonomy returns 404
- Flush Rewrite Rules when new site is created on network
- next_/previous_post_link() `in_same_category` appears to fail when true
- WordPress Custom Search by post_type
- Set templates for custom post types
- Main query not querying any posts in custom taxonomy template
- Include php on a specific page template
- Page Template Dropdown For Custom Post Types
- Which file/template is in charge of taxonomies for custom post types?
- providing access to post_id or post inside functions.php
- Custom Post Type setup
- Custom Post Type homepage template
- Archive Template being used instead of Category Template for Custom Post Type
- Custom Post Type Template Insert not working properply
- Display Posts Query with IF function
- Loop and add Specific Categories and Products Images
- custom post template ignored after altering permalinks
- Display ONE taxonomy and its assigned pages
- Modify Custom Post Type Slug
- Add custom template ‘sub-page’ to Custom Post type?
- Load info from customposttype into template page
- How can I create a button that when clicked populates a div with a list of foods that are checked as a certain type of ACF?
- custom post template design with dropdown option
- Custom post type single page uses the right template in preview mode but shows a different template after being posted
- Warning , Use of undefined constant PLUGIN_PATH?
- Post Attribute Section missing for Custom post type
- Showing Custom Post Type with his templates on a custom page template
- Displaying posts inside table having issues
- How to assign post to category
- Custom taxonomy with custom post type template not showing
- Values show up in custom home page but not in custom post pages
- How should i name the .php file to show custom posts under a taxonomy’s term?
- Organising custom taxonomies and custom post types
- Include template if a post is a single product
- Show index and not the archive for “Dog Custom Post” with default slug
- How to decouple custom post types components from template?
- Show Templates in Custom Post Type Editor
- template structure for CPT not clear
- Parent to another Custom Post Type – Template files not being recognized
- Templates list in “Page Attributes” metabox is inaccurate
- How to avoid hardcoded text in a custom page template?
- query_post while (have post) get_template_part()?
- Listing all custom post types using a specific term on the said term’s template page, in groups
- Problem retrieving custom field for a custom post type
- Only One Post of Custom Post Type Appearing on Template Page
- Page templates for custom post types
- Choose custom post type template by category
- How can I produce multiple webpages with a different output based on one entry/Page/custom Page?
- How to provide page_template path in custom plugin using WordPress