The code you provided works as expected on a fresh install of WordPress (4.3.1 in this case). The ideas below shouldn’t be considered an answer, so much as a checklist to aid in debugging the issue by narrowing the scope of the problem:
-
You’ll need to be logged in as a user with permission to view drafs to avoid a 404 or redirect.
-
Try disabling your plugins one by one to see if perhaps one of the plugins has established a conflicting rewrite rule.
-
Check your web server configuration (such as .htaccess on Apache) to see if there are any redirect rules in place there.
-
Finally, consider temporarily switching to another theme and adding your custom post type there to see if you get the same results. If a new theme solves the issue with your code, perhaps the conflicts all exist within your current theme.
Related Posts:
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Custom post type 404s with rewriting even after resetting permalinks
- Rewrite rule for Custom post type Monthly and Yearly archive
- Permalink rewrite 404 conflict- WordPress Taxonomies/ CPT
- Archive page with multiple taxonomies rewrite
- Modify custom post type rewrite rules in a separate function
- Help with a TV series Rewrite structure
- Taxonomy archives based on Custom Post Type
- Change page /2 to /transcript with a Rewrite
- Permalink rewrite with custom post type and custom taxonomy
- Permalinks for CPT breaks permalinks to pages
- Priority for Categories, Tags, Taxonomies, Posts, Pages and Custom Posts with same url
- Custom Post Types: pretty search URLs and has_archive
- Custom Post Type pagination when CPT ‘rewrite’ rule and a page have the same slug
- Custom Post Type rewrite redirects to homepage
- Adding paged query to custom URL rewrite
- WordPress rewrite my URL when i use pagination
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?
- how to add extra GET parameters to post to url with add_rewrite_rule?
- Parent & Child Taxonomy slugs in custom post permalink
- Remove url rewrites for registered taxonomies
- Rewrite slug of custom post type to include post-id
- Display posts from Custom Post Type in category page on front-end
- How to change custom post type permalink structure
- Front custom edit post page for each post
- Rewrite Question Mark in Post Template to Make it Pretty URL
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- Custom post type + category archive page
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Rewrites/query for multiple hierarchical custom post types
- CPT Template Not Showing – Getting 404
- How to get list of taxonomy slugs ordered parents>childs?
- remove base slug from hierarchical custom post type
- Rewrite Endpoints and CPTs – How to use in a plugin
- Make custom post types and pages place nice, re: rewrite
- add_rewrite_rule and passing variables for custom post types
- Use date in the URL of custom post type
- Get url.com/post_type/taxonomy/term work!
- Specific routing for CPT
- Rewrite rule for Custom post type Monthly and Yearly archive
- Best structure / rewrite rules to achieve the following url
- Add a permalink variable onto custom post type URL after post name slug
- Properly flush rewrite rules on plugin activation
- How to query 2 custom post types that need to share a slug?
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- Custom post type paging 404 error
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Set parent for custom post type archive rewrite url
- WordPress custom permalink and archive link for custom post type
- Custom Endpoint For Custom Post Type from Child Theme
- WordPress custom taxonomy page
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- Pages not appearing?
- Url Rewriting a dynamic wordpress page with parameters
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- How to properly set the rewrite rules for this case?
- Custom post type single page uses the right template in preview mode but shows a different template after being posted
- How to fix 404 on post after prepending Custom Post Type url with Custom Taxonomy Term slug
- Redirect Custom Post Type from Child Taxonomies
- Rewrite URL of Specific Post of Custom Type
- The page or ad listing you are trying to reach no longer exists or has expired
- Pagination URL in Custom Content Type
- Custom post type rewrite and wp_pagenavi interfering with each other
- Custom Post Type Rewrite – Page Not Found
- Custom Post Type rewrite url to /category/pagetitle [duplicate]
- Paging not working for hierarchical custom post type
- redirect old post type url to new structure url
- Multiple Custom Post Type permalink issue
- Custom Post Types and rewrite rules – One CPT works and a cloned one doesn’t
- Archive page for a custom post type using WPML
- Custom post type child page 404
- Permalink clashing with Custom Post Type rewrite rule
- How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
- CPT Template Not Showing – Getting 404
- What is the proper way implement a global $wp_rewrite?
- rewrite rules add a folder in the path
- Display results from two Custom Post Types in page template
- Canonicalization + Custom Post Types not working as expected
- Ideal top-level slug methods
- Custom Taxonomy in Permalink from post type
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- CPT Archive Pagination – Page not found
- How to add custom permalink struct with DYNAMIC author to a Custom Post Type
- add_rewrite_rule not working with custom post type
- Url rewrite with custom post type and taxonomy
- Paginate yearly archives for a custom post type
- Same slug for Custom Taxonomy archive and CPT archive – Rewrite rule not working
- Two Permalinks with one Taxonomy (custom taxonomy) and (custom post type -> custom taxonomy)
- What is the best way to relate different custom post types?
- Dynamic WordPress rewrite rules for multiple custom post types
- How to change rewrite slug for custom post type without conflicting w/ child pages of page with same slug
- Remove date rewrite rule for custom post type archive page
- Display content based on multiple URL parameters—pretty URL or query string