The post_type_link
hooks gets called for all links to custom post types, you are responsible for checking the link type. Remember to use the passed $post
object (not post ID), otherwise you check the current global $post
variable, which may not be the post for which you are creating a link now. So the code you added in your comment is almost correct, I would write it like this:
function cpt1_permalink( $post_link, $post, $leavename )
{
// Yoda condition to be safe
// http://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined/2430307#2430307
if ( 'cpt1name' != $post->post_type ) {
return $post_link;
}
// Rest of your code
}
Related Posts:
- Creating a custom public user page
- Multiple Permalinks for custom post type post
- Custom Post Type get_post_type_archive_link( $post_type ) returns false
- Custom Post Type rewrite
- Custom Permalink to remove category word , keeping posts permalink with date?
- Set a CPT slug as a base name for all the taxonomies
- Permalinks: custom post type -> custom taxonomy -> custom sub taxonomy -> post
- Menu Structure and URL structure, with Pages and Post-Type-Posts
- Making a custom help center page
- Custom taxonomy in URL showing 404
- get_object_taxonomies() returns empty array for custom post type
- Relative URLs for a particular custom post type?
- WordPress theme custom capabilities not works
- Custom Taxonomy URL are redirecting to page with the same name
- custom post type not showing in menu
- Custom posts don’t work
- How to have custom post type /example/ and then posts /example/posts.html
- Remove url rewrites for registered taxonomies
- Add archive slug to default post post type
- Custom Post type and permalink settings
- No posts found – Custom Post Type show_ui
- How to customize a permalink (URL) structure?
- Adding a custom post type taxonomy template in plugin
- Plugin: register custom post types, child ready and performance best practices
- How to add a custom taxonomy to show up in a custom post type menu?
- Rewrite slug of custom post type to include post-id
- Change custom post type slug from plugin options
- Rewrite rules for custom posts types
- Give a permalink to Custom Post Types without title
- Rewrite post type slug only for child theme
- wp_list_categories() – current-cat class also inside posts?
- Custom Post Types, URL rewrite on multiple CPTs
- How can we take into account post types when constructing permalinks?
- Getting template_include to work when allow_url_include is off?
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Get Taxonomy Term Title by it’s URL
- Taxonomy custom post type URL
- WordPress post_where & posts_join not working only for custom post type
- How to change custom post type permalink structure
- Add custom ID to CPT posts only create not update
- Add custom post type as submenu [closed]
- WordPress multiple custom post types capability conflict in a single menu
- Front custom edit post page for each post
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Categories of Custom Post throws gives 404
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- How to build custom route by adding taxonomies to URL ? ex: www.demo.com/communities/palo-alto/
- Getting meta in editor plugin, and event triggering issue
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- Orderby CPT custom fields not working
- How Can I Change the Custom Post Type Slug to the Taxonomy Slug in the URL?
- Use same slug base for Custom Post Type posts, and multiple taxonomy terms
- Unable to get Custom Plugin Options data
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Custom rewrite url category
- Rewrite Question Mark in Post Template to Make it Pretty URL
- Update post meta not working in transition_post_status
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- Use custom metabox to update automatically a post after a given date
- Index page with the same id as the slug
- How can I make the slug of the taxonomy also the slug of the custom post
- WordPress custom post type permalink rewrite shows page not found
- Using taxonomy term in CPT permalink – Pages 404’s
- Addition of custom option panel crashes Media Library & Admin Area
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Custom post type as home page with custom url
- Customize Custom Post Type URL
- How to rewrite url for any specific taxonomy?
- Custom post URL 404 error
- Programmatically rewriting slug through functions.php but returns 404
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- URL rewrite add author as base
- Form action/link to render a plugin in WordPress front-end
- What is the best practice for displaying my plugin content in themes?
- Custom post type archive page blank
- Add Custom Post type menu to another menu in specific location
- Custom taxonomy rewrite with query var returns %2F in URL
- WP Rewrite Rule Issue while using Custom post type & taxonomy
- Remove slug in URL custom post type
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrite custom post type url – Multiple post types
- Why isn’t my custom post type archive URL translating?
- Custom Post Type and Category Base Rewrite Issue
- Versioned Custom Post Type (Not the same as revisions)
- Rewrites/query for multiple hierarchical custom post types
- WordPress custom post type split into pages
- cpt and page sharing same base permalink
- WordPress uses url different from defined in rewrite arg of custom post type
- Rewrite URL of Custom Post Type for Jobs
- How to use TinyMCE Editor for one of my custom post meta field?
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- URL rewriting for CTP assigned entity
- How to Create a WordPress Plugin With Custom Post Type/Custom Field Features?
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- Custom post listing page layout of custom post type
- How to Get WordPress custom post data in WooCommerce product meta panel? [closed]
- Including taxonomy term before post type breaks top level pages