The problem must be how you define your post variable. You assume it’s the global $post but that’s not always the case especially in non-singular pages like archives.
The filter itself provides the correct post instance that’s it’s been called on as 2nd parameter.
function product_type_permalink( $post_link, $post ) {
// current post is already defined.
...
}
Also don’t get confused by the fact your code is in functions.php. It gets loaded on every WP page load, incl. in admin.
Related Posts:
- How to rewrite URI of custom post type?
- How to remove slug from hierarchical custom types in 3.5.2
- Custom post types – Use post_id in permalink structure
- Custom Post Type and Taxonomy URL rewrite
- Custom post type permalink: only use %post_id% and remove %postname%
- Rewrite custom post type rss feed links
- Is it possible to change the URL of custom post types to hide the post type slug?
- Archive page with multiple taxonomies rewrite
- rewrite get parameter with custom post type
- Taxonomy page returns 404 page not found
- Remove unwanted part of permalink custom structure from CPT url?
- How to have a custom URL structure for a custom post type?
- Display CPT taxonomies as an archive page
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Changing a custom post type “has_archive” after registered
- URL Design for Sub-Posts?
- Remove base slug in CPT & CT, use CT in permalink
- How do I list terms of a custom taxonomy at i.e. domain.com/brands/
- Permalink Structure problem with cpt and custom taxonomy
- Custom Taxonomy 404
- Custom Post Type rewrite redirects to homepage
- Custom Post Type slug same as page name causing a conflict
- single-{post_type}.php is not loaded despite flushing rules
- Adding paged query to custom URL rewrite
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Custom Permalink for Taxonimie and Custom Post Type
- Rewrite Custom Post Type URL slug
- Rewrite numeric ID parameter for hierarchical custom post type
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- Custom WP TItle from custom template with dynamic URL structure
- Rewrite rules for custom post type slug
- In WordPress how do you create a custom post type with the author’s name in the slug?
- Change URL of posts and also Custom Post Type
- Custom Post Type rewrite
- How can I display an archive of only one category of my custom post type?
- Permalink Structure CPT With Custom Taxonomy Fails
- Conditionally custom post type url rewrite
- Making a custom help center page
- Get Taxonomy Term Title by it’s URL
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- WordPress custom post type permalink rewrite shows page not found
- Using taxonomy term in CPT permalink – Pages 404’s
- Customize Custom Post Type URL
- Programmatically rewriting slug through functions.php but returns 404
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Why isn’t my custom post type archive URL translating?
- Custom Post Type and Category Base Rewrite Issue
- Rewrite URL of Custom Post Type for Jobs
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Specific routing for CPT
- Lost of query parameter when using permalink
- Custom permalink with child taxonomy terms
- Custom post type archive with page as parent url
- Pagination custom post type not working with rewrite slug
- Custom Rewrite Rule for Custom Post Type with URL Param
- WordPress custom slug rewrite
- WordPress Custom Post Type – Rewrite Query
- After creating Custom post type by user delete old one
- Set parent for custom post type archive rewrite url
- Dynamic CPT permalink structure based on ACF field value
- URL Rewrite – Page Archive
- Urls in Custom Post Type work for Terms but not for its Taxonomies
- Custom Post Types and Removing Slugs – should we do it?
- Taxonomy rewrite pagination 404
- custom post archive URL is wrong
- WordPress is ignoring my post rewrite rule
- Remove cpt slug from url and use custom taxonomy instead breaks all other cpt
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Duplicate content problems after adding an archive page to the article’s post type
- How to properly set the rewrite rules for this case?
- Redirect Custom Post Type from Child Taxonomies
- Custom post type structure + permalink structure
- Rewrite URL of Specific Post of Custom Type
- Using get_post_type with a custom URL format?
- Custom post type rewrite and wp_pagenavi interfering with each other
- Show index and not the archive for “Dog Custom Post” with default slug
- 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
- Custom Post Type URL Rewriting
- Archive page for a custom post type using WPML
- Why is a custom post type’s URL “/?cposts=name-of-the-post” but default post’s URL is “/?p=ID”?
- Customize category URL
- rewrite rules add a folder in the path
- How can you preserve URLs when moving posts to a custom post type?
- Custom Post Type Base URL
- Custom Taxonomy in Permalink from post type
- Custom Post Type and single-posttype template
- How to rewrite custom slugs that follow my rules
- Custom post type with custom taxonomies structure url not working archive of CPT
- What is the best way to relate different custom post types?
- Allow child pages with the same base as the CPT slug
- How to work with URLs where sometimes a post or a subcategory is in the same part of the URL structure
- How to make 2 (or more) custom post type post pages sit under the same slug?
- Remove date rewrite rule for custom post type archive page
- Display content based on multiple URL parameters—pretty URL or query string