Change your rewrite to add the course query var:
'rewrite' => array('slug' => 'course/%course%')
Then filter post_type_link to insert the selected course into the permalink:
function wpa_course_post_link( $post_link, $id = 0 ){
$post = get_post($id);
if ( is_object( $post ) ){
$terms = wp_get_object_terms( $post->ID, 'course' );
if( $terms ){
return str_replace( '%course%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
add_filter( 'post_type_link', 'wpa_course_post_link', 1, 3 );
There are also plugins like Custom Post Type Permalinks that can do this for you.
Related Posts:
- Adding categories to custom post type in permalink
- How to change permalink structure for custom post type and it’s taxonomies?
- Is there a way to use regular categories with custom post types?
- On clicking on the category name the page is redirecting on 404 pge
- How to show custom taxonomy in the permalink?
- Custom post types and permalink
- Get a permalink structure of /%posttype%/%category%/%postname%
- Possible for Category Base and Custom post Type to share the same slug/permalink?
- Custom Post Types and independent Categories – complex Taxonomy
- Add custom post type settings to wordress default posts
- Can’t remove front from permalinks for custom taxonomy category page
- Remove CPT name from permalink but add %category% instead
- Custom Post Type with modified permalink structure results in 404
- Custom post type category permalinks and archive pages
- Searching in multiple category + URL hierarchy in real estate WordPress site
- Modify category permalink to use post type slug
- Category permalinks don’t work even after flushing
- Adding categories to custom post type in permalink
- how to use two permalinks for one custom post type based on categories
- Get full control over custom post type url
- How to switch from custom post type URL to category URL?
- Custom Post Type + Category archive
- Category / Custom Post Type permalink issue
- Custom Post Type Permalinks with %category%
- Remove slug from Custom Category Permalink + dual-category permalinks
- Custom post type and category permalinks
- Is it possible for post and custom post type to share a category base slug?
- How to get the proper category in permalink with custom post type assigned to multiple categories
- Showing posts from different categories and from custom post type
- Custom post type getting wrong categories and tags
- How to hook custom taxonomies to custom post types and make the permalinks work?
- custom post type parsed as attachment
- Categories of custom taxonomy don’t show any posts
- How to display custom taxonomies with links in filter menu?
- Show a Category X’s custom post type on Category X archive page?
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- WordPress Custom Post Type Repeated 404 Errors
- Child post with numeric only slug keeps redirecting to parent
- How to change custom post type permalink structure
- Custom post type url with category
- Help with Elementor Pagination CPT archive 404 problem
- PHP variable not regenerating when publishing multiple posts at the same time
- Adding custom post category slug in permalink causes 404 error for pages and posts
- How can I use get_post_meta with add_rewrite_rule to build custom permalinks?
- Allow post/page hierarchy across different post types?
- Multiple level category drop-down from the WordPress dashboard
- Permalink for a custom post type isn’t working and I don’t know why
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Can’t get custom rewrite tag, query var, permastruct (permalink structure), and rewrite rule to work properly together
- 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
- WordPress Custom Post Type Permalinks dynamic term slugs
- 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
- Hide parent categories when clicked, and show it’s childs
- Limit amount of posts made within a custom taxonomy
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- Problem with displaying posts in the CPT category
- 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
- Filter CPT posts by one or more categories
- Getting categories of posts under a custom taxonomy
- Custom Post Types with a common category for a blog listing
- Assign same parrent Page to pages AND custom post types
- How to get categories linked in posts for a specific post type
- WordPress custom post type permalink rewrite shows page not found
- How to set a CPT to have a page as a parent, then rewrite urls accordingly?
- Completely remove custom post type permalinks (“One Page” website)
- Using taxonomy term in CPT permalink – Pages 404’s
- Removing custom post type slug from URL
- Custom post type, organized by categories
- How to display “Category and Post_tag” component in a CPT Gutenberg edit screen?
- 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
- Create a custom php page and load it at a specific slug
- URL rewrite add author as base
- Set a checkmark in a category based on a URL-parameter
- Permalinks /country/city/cpt/postname/
- Custom Permalink to remove category word , keeping posts permalink with date?
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- Seamless permalinks between Custom Taxonomy and Custom Posts
- WP Query with categories only shows one post and ignores the category
- Custom post type and custom taxonomy with the same slug using the file page taxonomy only as directory
- Need help with permalink rewrites for Custom Post Types with hierarchical relationships
- Custom Post Type Permalink empty
- Adding custom post type to count in category
- Custom Permalinks with CPT and Hierarchical Taxonomies
- How to edit this code to get the categories in achieve page?
- Category with post type pagination returns 404
- Custom Post Type and Category Base Rewrite Issue
- Get the category from custom post type
- Post injections into Site Origins Page builder [closed]
- Change custom post type permalink to show name of post from another custom post type?
- Custom Post Type Permalink
- Custom Post Type + Categories
- How to create a gallery page with categories?
- Permalinks for custom post type