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:
- Mixing custom post type and taxonomy rewrite structures?
- How to rewrite URI of custom post type?
- Custom rewrite rules for archive page and single post
- WordPress Rewrite Rules for Custom Post Type and Taxonomy
- Custom post types – Use post_id in permalink structure
- How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy
- Custom Post Type and Taxonomy URL rewrite
- Custom post type permalink: only use %post_id% and remove %postname%
- Rewrite custom post type rss feed links
- Add category to custom post URL
- Creating a custom public user page
- Archive page with multiple taxonomies rewrite
- rewrite get parameter with custom post type
- How to filter custom post type archive by meta value
- Taxonomy archives based on Custom Post Type
- Multiple custom post types using the same taxonomy = URL frustrations
- Taxonomy page returns 404 page not found
- Child pages on hierarchical Custom Post Types 404s
- Remove unwanted part of permalink custom structure from CPT url?
- How to have a custom URL structure for a custom post type?
- Permalinks for CPT breaks permalinks to pages
- WordPress custom post type url change
- Changing a custom post type “has_archive” after registered
- Possible to change the slug of default post type?
- Custom Post Type rewrite redirects to homepage
- Custom Post Type slug same as page name causing a conflict
- Adding paged query to custom URL rewrite
- Custom Post Type rewrite rules not working, how to alter the rewrite order?
- Rewrite Custom Post Type URL slug
- Customising rewrite rules for CPT single post URL to work as paged URL
- Remove custom post type slug not working for child pages
- Custom WP TItle from custom template with dynamic URL structure
- Rewrite rules for custom post type slug
- Change URL of posts and also Custom Post Type
- Custom Post Type rewrite
- Relative URLs for a particular custom post type?
- How to have custom post type /example/ and then posts /example/posts.html
- Remove url rewrites for registered taxonomies
- Change custom post type slug from plugin options
- How can we take into account post types when constructing permalinks?
- 404 Issue w/ Custom Post Type – using Meta for Permalink rewrite
- Get Taxonomy Term Title by it’s URL
- How to create custom url structure based on custom post type rewrite slug, taxonomy and category slug?
- Custom rewrite url category
- Using taxonomy term in CPT permalink – Pages 404’s
- How to add rewrite rule to custom post type with parent in url with cpt ui?
- Programmatically rewriting slug through functions.php but returns 404
- How do I change the custom taxonomy slug to be the same as the custom post type slug?
- Custom Permalinks with CPT and Hierarchical Taxonomies
- Rewrite custom post type url – Multiple post types
- Why isn’t my custom post type archive URL translating?
- Rewrites/query for multiple hierarchical custom post types
- Post Type rewrite rule to point to custom Page/template
- Custom Permalink Structure for Custom Post Type, Custom Taxonomy, Under a page
- Rewrite rule for Custom Post Type Page as a parent
- Ignoring slug capitalization on rewrite rule for custom post type archive page
- Taxonomy in URL
- Custom URLs in post types make it impossible to view archive
- Custom Permalinks for Custom Post Types
- Postname on unique permalink structure appends “-2” for a custom post type. How can I get this to stop happening?
- Share root slug for Child Page and Custom Post Type (prioritizing child pages over posts)
- Route subpage to Custom Post Type
- Custom Post Type Category URL
- Custom Post Type Advanced Slug
- Rewrite permalink for multiple post types (CPT) with taxonomy term
- How to constrain the results to a specific post_type on tag archive page?
- Pagination for custom post types – url rewriting
- Modifying rewrite rules to use /category//
- Custom Post Type Date Based Archive URL rewrite [duplicate]
- Custom rewrite rule takes place AFTER the generic category rule
- returning the currect URL for nested posts
- Adding /blog in front of single posts (only)
- multiple URLS for the same page
- 404 error rewrite permalinks
- Custom rewrite rule based on other custom post type title
- How to apply multiple rewrite_rule to a single custom post type url?
- Define multiple prefixes for custom post type
- Custom Post Type parent/child relationship rewrite rules for permalinks
- Add %post_id% to slug of custom post type and prevent the “unique slug” thing that WP does?
- Custom Post Type canonical link / pagination redirecting to root
- Rewrite url post_tag for custom post type
- How to build overlapping custom post_type and taxonomy rewrites without conflicts?
- WordPress custom post type rewrite rule matches all pages returning 404
- Remove custom post type slug but keep related category taxonomy permalink
- page not found for example.com/custom-post-name
- Force WordPress to only match URL in category
- Custom post type with parent page? Possible?
- current_menu_parent for custom post type and custom url
- Why won’t this rewrite rule work?
- Parent cpt/child custom post type URL permalink relationship
- Cannot modify a registered custom post type rewrite slug
- Custom post type and custom taxonomy archive inaccessible
- Generating custom URL before post is published
- Custom post type permalink structure
- How can i change url structure of cpt like this?
- Rewrite Rule for custom post type link with or without taxonomy terms
- How to rewrite custom slugs that follow my rules
- Custom post type with custom taxonomies structure url not working archive of CPT
- What is the best way to relate different custom post types?
- Allow child pages with the same base as the CPT slug