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 do I get the permalink of a custom post type?
- WordPress 3.3 custom post type with /%postname%/ permastruct?
- Why does a custom post type need the ”hierarchical’ args setting?
- Permalink rewrite with custom post type and custom taxonomy
- how do I group content in magazine-style ‘issues’?
- Custom Post Type with Nested Taxonomy and Template Files
- Use standard WordPress categories with a CPT
- Semantic URL Custom Post Type and Taxonomies permalinks
- How can I add single catogory for custom post type?
- Get the post_type of current taxonomy or category page
- Categories and Tags not working!
- get_categories() for only CPT
- category.php displays ALL posts instead of just those with the current category
- custom taxonomy archive by year
- Display Next/Prev when looping Custom post-types archive?
- How much control do we have over CPT rewrite slugs? Can I create a “root” page for my CPT with out the page path, and then have paths for other pages?
- Weird problem happening with custom taxonmy when creating/updating posts
- Removing parent slug in hierachial custom post type
- Wrong generated page_name/slug on first publish of custom post type
- CPT Archive with core Category
- get_posts() with custom post type does not work outside page.php
- Why doesn’t a custom post type permalink ever hit index.php
- Allow post/page hierarchy across different post types?
- Multiple level category drop-down from the WordPress dashboard
- How can achieve this permalink perfectly? domain.com/%category%/%post-name%
- custom-taxonomy/post_name instead of the default post_type/post_name
- Getting categories of posts under a custom taxonomy
- How to get categories linked in posts for a specific post type
- Custom Permalink to remove category word , keeping posts permalink with date?
- Rewrite Rule for showing Parent/Child Relationship between Two Hierarchical Custom Post Types
- How to edit this code to get the categories in achieve page?
- Get the category from custom post type
- Custom Post Type Permalink
- Cross reference custom post types
- Make a custom_post translatable
- Custom Post Fields at the beginning of a Custom Permalink
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Custom templates for a specific category
- I’m having trouble getting the permalink sample on my custom post type edit page to work
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- Custom Post Type to replace Woocommerce products – page not found error
- CPT, meta-data, url parameter
- Change permalinks for custom post type based on taxonomy term
- Custom post not appearing under custom taxonomy category
- If custom category search then page 2 not found
- WP 3.1 custom post type permlinks
- Finding the CPT archive template source
- How to prefix custom post type URL with custom post taxonomy term?
- CPT and rewrite rules
- Custom post type single with custom URL structure
- Get posts in custom post type categories
- Some permalinks on Apache/localhost development setup return 404’s when set to anything other than plain permalinks
- Use Category for Custom Post Type – But Need Another Separate Archive Page too
- Two CPT: one is using part of the custom rewrite slug from the other
- Custom permalink with custom taxonomies for custom post type
- Only show current category post
- Multiple custom post type and permalink issue
- Remove sequential number from permalinks
- Page to show custom posts and one category
- Have two (permalinks) urls for a same custom post type
- change precedence of permalink for post_types?
- Redirect permalinks after creating custom post types
- How to make nested custom post type slugs work
- Custom Post Type Permalinks Problem
- Problems with custom post type and hierarchical permalinks
- Bulk remove category from custom post type?
- Problem with menu categories doubling up when updating database?
- Posts picking up old Permalinks, how to reset?
- WordPress Set A Static Page/Template For All Sub-Pages
- How to query posts by category with the_title();
- Can WordPress show posts based on a button that the user clicked 2 pages back?
- Custom Post Types Permalink