Think ive solved it and can’t believe what it was!
On my rewrite rule I had:
add_rewrite_rule(
'custom-post-type/([0-9]+)/([^/]*)/?$',
'index.php?post_type=customposttype&p=$matches[1]',
'top'
);
Adding in and passing the post_name for the custom post type got it to start redirecting.
add_rewrite_rule(
'custom-post-type/([0-9]+)/([^/]*)/?$',
'index.php?post_type=customposttype&p=$matches[1]&customposttype=$matches[2]',
'top'
);
Anycase for now its late and it seems to have started working 🙂 Now at least it forces the 301 from the fake post to the real post as was previously put in canonical meta. Don’t know why but thought if the id was provided it would have worked without having to take in the post_name.
Sometimes WP can really have you pulling your hair out!
Related Posts:
- Can a custom post type have a Parent Page?
- Where, When, & How to Properly Flush Rewrite Rules Within the Scope of a Plugin?
- Custom Post Type Permalink / Rewrite not working immediately
- CPT Template Not Showing – Getting 404
- add_rewrite_endpoint() not working for custom post type archives
- Adding meta values to permalink
- Permalinks so that one custom post type appears to be a child of another, not working
- How to achieve this permalink -> category-name/custom-post-type-name/post-name
- WordPress Custom Post Type Category Page
- How to Add Pages Under Custom Post Type URL Structure?
- Prepend meta_value to permalink of post
- How to check if last uri segment is a custom post type or taxonomy term?
- Pagination Doesn’t Work
- Rewrite custom post type url’s adding meta box values
- Permalinks using event date (year & month) instead of publication date
- Multiple parameters in a custom post type url rewrite
- WP Rewrite Rules – Custom post type & taxonomy
- Need help with complex custom post type setup
- WordPress monthly archive links result in 404
- Remove base slug in CPT & CT, use CT in permalink
- Rewrite rules for custom post type ‘attached’ to another custom post type
- Disabling post_type in URL
- single-{post_type}.php is not loaded despite flushing rules
- Custom Permalink Tag breaks Pagination
- Custom Permalink for Taxonimie and Custom Post Type
- how to get archive urls with same origin for custom types and terms?
- Rewrite numeric ID parameter for hierarchical custom post type
- Adding the taxonomy before the custom post type
- add_rewrite_endpoint() and Custom Post Type Archive
- Pagination problem
- Custom post type with slug for plural (archive) and for single
- add_rewrite_rule and how to get the custom post into the worpress loop the correct way
- Permalink Structure CPT With Custom Taxonomy Fails
- Rewrite WordPress URL to show CPT meta field data
- Custom Post Type won’t Register
- Making a custom help center page
- Custom rewrite rule for hierarchical custom post type
- Rewrite and custom post type: order by custom field not working
- Am I using the flush_rewrite_rules function in the right place?
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Adding Post id to the end of slug in a Custom Post Type
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- Customize Custom Post Type URL
- Custom taxonomy rewrite with query var returns %2F in URL
- cpt and page sharing same base permalink
- Hide or disallow default custom post type url?
- A case for Hierarchical Custom Posts
- Rewrite CPT child page URL to support query var
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Flush Rewrite Rules when new site is created on network
- Pretty URLs and custom post types
- Specific routing for CPT
- Rewrite rule for Custom post type Monthly and Yearly archive
- Best structure / rewrite rules to achieve the following url
- Properly flush rewrite rules on plugin activation
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- Custom post type paging 404 error
- Custom Post Type – Rewite Archive page
- Set parent for custom post type archive rewrite url
- How to rewrite the post slug of a custom post type post
- Custom Endpoint For Custom Post Type from Child Theme
- Custom post types and custom variables — add_rewrite_tag() not working
- Add Custom Values to Permalinks Through Custom Fields and Posts
- Why do I need to register my custom post type a second time when flushing rewrite rules?
- Custom post rewrite rule not working
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- WordPress rewrite rule doesn’t work unless post category is explicitly called in regex
- Url Rewriting a dynamic wordpress page with parameters
- How to make a post accessible from multiple post type slugs?
- Custom Post Type add_rewrite_rule
- Sudden 404 pages on product category archives
- Change CPT permalink to use the category
- add_rewrite_rule wordpress ignoring url pattern, wp rewrite not working
- Redirect Custom Post Type from Child Taxonomies
- Pagination URL in Custom Content Type
- Custom post type rewrite and wp_pagenavi interfering with each other
- Custom taxonomy archive slug overwrites static page
- Group based routing and administration
- Adding Custom Taxonomy Along-with Post Name in Post Type Permalink
- 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
- Custom post type child page 404
- Custom post type rewrite with_front
- How to rewrite CPT-Permalinks the correct way (incorporating meta-box-data)?
- Rewrite Rule & Regex – Extract ‘cat-name’ and ‘page-number’ from http://domain.com/custom-post-type/category/cat-name/page/page-number
- CPT Template Not Showing – Getting 404
- What is the proper way implement a global $wp_rewrite?
- Display results from two Custom Post Types in page template
- Permalink of Custom Post Type
- Ideal top-level slug methods
- Custom Taxonomy in Permalink from post type
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- add_rewrite_rule not working in Custom Post Type UI Plugin
- CPT Archive Pagination – Page not found
- add_rewrite_rule not working with custom post type
- Custom archive URL as a subfolder of the custom post type slug
- Two Permalinks with one Taxonomy (custom taxonomy) and (custom post type -> custom taxonomy)