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]
- Theme localization of “slugs” (custom post types, taxonomies)
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Remove slug in taxonomy url
- Taxonomy, Terms, and Template Files
- Disable permalink on custom post type
- Pagination throws 404 error on custom taxonomy archive pages
- custom post type and custom taxonomy permalink
- Is there a way to use regular categories with custom post types?
- Hierachical Custom post types permalinks not working
- Custom Post Type Permalink For Parent/Child, 404 Page Not Found Error
- Rewrite permalinks for custom posttype and custom taxonomy
- How to check if last uri segment is a custom post type or taxonomy term?
- Custom taxonomy & post slug permalink
- Including two taxonomies in a permalink structure
- WP Rewrite Rules – Custom post type & taxonomy
- Removing CPT slug from URL results in 404 error for archive page
- Remove base slug in CPT & CT, use CT in permalink
- Permalink Structure problem with cpt and custom taxonomy
- Custom Taxonomy List links being re-written
- Custom Post Types, Custom Taxonomies and Permalinks ?
- Custom Taxonomy 404
- Custom post type permalinks giving 404s
- Custom Taxonomies: Multiple Hierarchical Permailnks For A Single Post + Prev/Next Links
- Add the .html extension to custom post types
- Can’t edit Custom Post Type slug/permalink
- What is better: Custom Fields vs Custom Taxonomies with Terms for perfomance, scalability and better user experience
- Custom Permalink Tag breaks Pagination
- Custom Permalink for Taxonimie and Custom Post Type
- Custom post types and permalinks
- Automaticly add slug to posts
- Permalink Structure CPT With Custom Taxonomy Fails
- Custom post type and taxonomy slug issue
- Does WordPress limit the length of slug names for Post Meta or Terms?
- Bizarre Permalinks Issue: 404 Errors Everywhere
- Use different taxonomies in different custom post types’ permalinks?
- Custom template won’t load for a custom post type (custom permalinks used)
- Custom Post Type / Two level deep taxonomy (cat. and subcat.) uri problem (error 404)
- How to hook custom taxonomies to custom post types and make the permalinks work?
- Child post with numeric only slug keeps redirecting to parent
- Help with Elementor Pagination CPT archive 404 problem
- 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?
- 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 Permalinks with CPT and Hierarchical Taxonomies
- 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 post type archive pagination 404
- Custom post type, permalinks, taxonomies and blog posts
- Custom permalink with child taxonomy terms
- How do you create %post_type%/%postname%/ permalink structure?
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- Different slug taxonomy for two different CPT
- How to get all posts related to particular category name on button click?
- Changing CPT slug and taxonomy already registered in parent theme
- WordPress custom permalink and archive link for custom post type
- Need to return a string as permalink insted of str_replace
- Custom Post Type Child Won’t Come Through With Pretty Permalinks
- Custom post type and multi taxonomies + customize url
- Custom Permalink For Custom Post Type – Working Fine But Broken For Pagination
- Use custom post type taxonomy between cpt slug and name
- Custom taxonomy returns 404 even with saving permalinks
- How can I get custom post types to recognize pretty permalink variables?
- How to change URL structure for custom post type in wordpress? Custom taxonomy + custom Post name [duplicate]
- Remove CPT Slug with 2 taxonomies and 1 post meta
- How to structure a website with custom post types and custom taxonomies?
- WordPress page not showing up – replaced with last 10 posts?
- Custom Post Type Taxonomy – Permalinks generating, but posts not found
- Custom taxonomy in custom post type archive with pagination
- Custom Post type and Taxonomy in post URL error
- How to retrieve the permalink for a specific (custom) term?
- Permalink Trouble with Custom Post Type
- WP Query WordPress Post Type with the same Taxonomy name
- Custom Post Type with multiple Custom Taxonomies / Hide Taxonomy Slug from URL
- Is it possible to use a post name in a custom post slug?
- Taxonomy Archive URL + Template