If you’re running WordPress 3.0.1 or later, I believe your problem lies with the ‘post_type_link’ filter declaration and function arguments.
When the ‘post_type_link’ filter is applied, it passes the following 4 arguments:
apply_filters('post_type_link', $post_link, $post, $leavename, $sample);
But your function accepts $post_link and $id.
Try the following adjustments:
function custom_post_link( $post_link, $post ) {
if ( $post->post_type != 'course-segment')
return $post_link;
$course="course-segment";
if( $terms = wp_get_object_terms( $post->ID, 'course' ) )
$course = $terms[0]->slug;
return str_replace( '%course%', $course, $post_link );
}
add_filter( 'post_type_link', 'custom_post_link', 1, 2 );
Related Posts:
- Custom Post type & Taxonomy URL structure
- Combining Multiple Taxonomies in one URL
- Dynamic taxonomy in permalink made all other posts NOT FOUND?
- Remove Slug from Custom Post Type results in 404
- Remove taxonomy slug when not assigning taxonomy with custom post types
- Remove Taxonomy Slug when No Taxonomy is Assigned to Custom Post Type?
- Custom Taxonomy breaking pages permalinks
- custom post type and custom taxonomy url conflict
- Custom Post Type with two hierarchical Custom Taxonomies: strategy to generate best permalink structure
- Custom taxonomy in URL showing 404
- Custom post type permalink tag 404
- Hierarchical permalinks for custom post type and taxonomy
- How to solve this custom post type goes to 404 page?
- Custom Post Type Advanced Slug
- How to filter a custom post type by custom taxonomy without 404
- Safe to throw 404 error in request filter?
- Custom post type URL structure with site.com/custom_taxonomy_slug/post_name
- Remove Custom Taxonomy Slug only without removing Custom post type slug in permalinks
- 404 Error On Custom Taxonomy Pages 2, 3, etc
- Hide custom post type slug url from search engine [closed]
- Child post with numeric only slug keeps redirecting to parent
- Custom post type url with category
- Help with Elementor Pagination CPT archive 404 problem
- Adding custom post category slug in permalink causes 404 error for pages and posts
- Permalink for a custom post type isn’t working and I don’t know why
- 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
- How to have the same url structure for both a CPT and a Taxonomy?
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- create a subcatagory for a custom post type and out put url as posttype/subcategory/item
- custom-taxonomy/post_name instead of the default post_type/post_name
- Show custom post archive when custom post not specified
- Show custom post type relationships by taxonomy
- How can I make the slug of the taxonomy also the slug of the custom post
- Assign same parrent Page to pages AND custom post types
- Can’t remove front from permalinks for custom taxonomy category page
- Allow duplicate slugs for custom post type with taxonomies
- Using taxonomy term in CPT permalink – Pages 404’s
- Removing custom post type slug from URL
- Nested Custom Post Type or Custom Post Type Parents?
- Customize Custom Post Type URL
- Custom post URL 404 error
- Create a custom php page and load it at a specific slug
- Permalinks /country/city/cpt/postname/
- Seamless permalinks between Custom Taxonomy and Custom Posts
- Custom post type and custom taxonomy with the same slug using the file page taxonomy only as directory
- Custom Permalinks with CPT and Hierarchical Taxonomies
- How to prevent a CPT’s slug and page slug from conflicting with each other?
- How to have this permalink structure: post_type/postname/custom_inner_page
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Custom taxonomy returns 404
- Including taxonomy term before post type breaks top level pages
- Parent Page and Breadcrumb URL’s for Custom Post Types Not Working
- Permalinks: custom post type -> custom taxonomy -> post
- Custom post type archive pagination 404
- CPT’s with landing page instead of archive – Url Rewrite?
- How to change permalink to include custom post type
- Custom post type, permalinks, taxonomies and blog posts
- Custom post type / taxonomy rewrite archive page 2 gives 404
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- permalink /category/post-name with custom post type and taxonomy
- Custom post type and taxonomy permalinks
- set permalink for CPT
- Top Level pages in wordpress giving 404, but child pages working fine
- Custom Post Type – Duplicate Page Slugs
- Custom permalink with child taxonomy terms
- Custom post type Permalinks with hierarchical Taxonomies
- 404 in custom post type feed with mistake permalink
- Custom post type pagination 404
- Remove permalink for custom post type
- Best way to specify “article type” in URL
- Custom post type single page (single-{CPT-name}) 404 when slug includes hyphens
- Template files for Custom Post Type and Taxonomy
- How do you create %post_type%/%postname%/ permalink structure?
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- Rename a slug label
- Different slug taxonomy for two different CPT
- Can’t use pagination with custom taxonomy
- How to add current custom taxonomy slug to body class
- Using page slug in wp_query
- Custom taxonomy page returns 404
- Listing all slugs?
- Template for custom post type when taxonomy is in the URL
- One Custom post type 404’s others don’t
- Permalink problems with custom post type and custom taxonomy
- Custom taxonomy template list not working (404)
- Custom post type permalink returns 404 when set to private
- Custom post type slug 404
- How to get all posts related to particular category name on button click?
- Post type Permalink
- Changing CPT slug and taxonomy already registered in parent theme
- Custom Post Type to replace Woocommerce products – page not found error
- WordPress custom permalink and archive link for custom post type
- Custom post type categories gives 404 error
- Ideas on how to organize a project [closed]
- Enabling permalinks disables custom page template
- Need to return a string as permalink insted of str_replace
- Change permalinks for custom post type based on taxonomy term
- Under What Conditions Can I name my CPT the same as my CPT Page?
- Using page title as a link to term archive