You can filter the slug creation on wp_unique_post_slug hook.
//Register the filter
add_filter('wp_unique_post_slug','prefix_the_slug',10,6);
function prefix_the_slug($slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug){
//Get value from the custom field
$prefix = get_post_meta($post_ID,'cw_event_start_date',true);
//Only prefix certain post type and if prefix field existed
if($post_type==='post' && $prefix && !empty($prefix)){
//Prefix only if it is not already prefixed
preg_match ('/^\d\d\d\d\d\d/', $slug, $matches, PREG_OFFSET_CAPTURE);
if(empty($matches)){
return $prefix.'-'.$slug;
}
}
return $slug;
}
Related Posts:
- Rewriting a custom-post-type permalink with taxonomy term?
- Remove custom post type slug from URL
- Custom post type, no need for single view, plus want permalink rewrites that include hash in URI
- Custom post type yearly/ monthly archive permalinks
- Using /%postname% for a custom post type
- Changing the URL Structure of a Paginated Custom Post
- Removing base slug from hierarchical custom post type
- Rewriting ‘rewrite’ slug for custom post type used by plugin
- Adding meta values to permalink
- Custom post type taxonomies URL rewrite
- WordPress custom taxonomy URL rewrite on spelling errors
- How can i avoid the permalink start with ‘blog’ while using the custom post type?
- Custom Posttype Inheritance (and url structure)
- Permalinks so that one custom post type appears to be a child of another, not working
- Create permalink structure for one taxonomy archive per custom post type
- Adding %author% in custom post type URL structure?
- Custom post type’s get_permalink returns wrong url
- Custom post type permalink structure with the category also acting as an archive
- Prepend meta_value to permalink of post
- Defining a default page for custom post type
- Pass parameter to custom post type single while keeping clean url
- Rewrite custom post type url’s adding meta box values
- Multiple parameters in a custom post type url rewrite
- URL rewrite and navigation structure for wordpress custom post type
- Removing CPT slug from URL results in 404 error for archive page
- Many to Many Taxonomies or rewrite rules?
- How to properly prefix blog post URL’s
- remove post-name from title in custom post type
- Getting Post ID from slug during init
- Rewrite custom post & taxonomy to share same URL path
- how to use two permalinks for one custom post type
- Adding a date archive to Custom Post Type
- Custom Post Type/ Taxonomy URL rewrite
- Bulk 301 redirect for custom post type
- Custom Permalink Tag breaks Pagination
- how to get archive urls with same origin for custom types and terms?
- Permalinks for Taxonomy and Custom Post Type
- Share parent path between Custom Post Types and Pages?
- multiple url slug for single custom post type
- Pretty URLs for Custom Post Type & Custom Taxonomy with Duplicate Slugs on WPML
- Custom Post Type and Custom Taxonomy Permalinks
- Custom Post Type Post have a Child `Page` Post Type Post
- remove permalink “front part” for custom post type
- Change Permalink Structure for Tag.php template
- Change custom post type slugs, with category/taxonomy before post type name
- Rewrite post type slug only for child theme
- wp_list_categories() – current-cat class also inside posts?
- 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?
- How can I make the slug of the taxonomy also the slug of the custom post
- Set a CPT slug as a base name for all the taxonomies
- Custom taxonomy rewrite with query var returns %2F in URL
- Remove slug in URL custom post type
- Versioned Custom Post Type (Not the same as revisions)
- cpt and page sharing same base permalink
- Custom post Type, child of a Page?
- Hide or disallow default custom post type url?
- URL rewriting for CTP assigned entity
- Added Custom Post Type and the View Option Doesn’t Work
- Permalink structure with custom taxonomies and custom post type like /parent-tax/child-tax/custom-post-type-name (with no base name)
- Pretty URLs and custom post types
- Best way to specify “article type” in URL
- How to have permalink like domain.com/term/postname?
- post_type_link Filter – Too Few Arguments
- Dynamic CPT permalink structure based on ACF field value
- WordPress rewrite url
- url rewriting for custom post types
- Post type Permalink
- Add Custom Values to Permalinks Through Custom Fields and Posts
- Archive page for custom post type and custom taxonomy
- Rewrite rules for custom post type
- Custom taxonomy and post type rewrite rules
- Combine 2 different custom post slugs into a single permalink?
- Custom Post Type and Taxonomy Rewrite Error
- custom posts permalinks url rewriting
- Url Rewriting a dynamic wordpress page with parameters
- Setting Parent Page to Post
- Add rewrite rule for custom post type single page
- Custom taxonomy terms as children of multiple custom post types
- I want to rewrite the URL of a specific post with a specific custom field to easily analyze in Google Analytics
- Custom Post Type & Taxonomies – Rewrite
- Display CPT taxonomies as an archive page
- Change CPT permalink to use the category
- CPTUI rewrite disable when no post in CPTUI has been found
- add_rewrite_rule wordpress ignoring url pattern, wp rewrite not working
- Rewrite of Custom Post Type doesn’t work with dynamic data
- Set archive of custom post type like ‘posts’ page in reading settings is set
- Custom URL for Custom Post Type & Custom Taxonomy Term
- Custom taxanomy and custom post type – pagination leads to 404
- Register post type getting error 404
- Flush rewrite rules when new cpt is registred
- Custom post url in search.php isn’t the correct rewrited url
- CPT url rewriting : regular posts return 404 error
- Custom WordPress URL
- One custom post type with two different url structure base on taxonomy term
- URL Rewrite Adjustment for Custom Post Type causes template to revert to index.php
- Custom Post Type – Rewrite slug [duplicate]
- Rewrite rules for using the same base slug for multiple content types
- add_rewrite_rule not working in Custom Post Type UI Plugin
- Menu Structure and URL structure, with Pages and Post-Type-Posts