you can use the post_type_link
hook. and then add a custom rewrite rule to your register_post_type
function:
function replace_post_link( $post_link, $id = 0 ){
$post = get_post($id);
$post_type = get_post_type( $id );
if( is_object( $post ) && $post_type == 'events' ){
$custom_date = get_field('YOUR_CUSTOM_FIELD');
return str_replace( '%custom_date%' , $custom_date, $post_link );
}
return $post_link;
}
add_filter( 'post_type_link', 'replace_post_link', 1, 3 );
and add to register_post_type
:
'rewrite' => array( 'slug' => 'events/%custom_date%', 'with_front' => false )
make sure to flush your rewrite rules when you are done by going to: Settings > Permalinks and clicking ‘save changes’
Related Posts:
- Menu Link Redirect Based on Username or User ID
- Why I can’t change the permalink of this page?
- How to get this JavaScript working with get_permalink
- How can I make my .htaccess file writeable by wp-admin?
- Automatically append ID to at the end of specific URLs
- Editing Pages Give 404 Error After WordPress Upgrade in Admin Panel
- Change in permalink structure made javascript cookie not work correctly
- WordPress Installed But Not Showing Up! [closed]
- How to Custom Edit Post Title & Permalink Slug?
- Broken wordpress site, non-working links and no access to wp-admin page
- how to get permalink
- Gutenberg Editor: dynamically edit slug field based on ACF field
- Fatal Error when trying to load Permalinks page on WP admin [closed]
- Edit Post Permalink option removed, looking for possible causes
- All files in public_html, Cannot launch WordPress site via wp-admin
- 404 page not found – Yet open admin page it works
- Where is wordpress redirecting wp-admin/admin/dashboard to wp-admin and how to turn it off
- Change permalink when page category selected in admin
- Change default URL (or permalinks) in the back-end
- Stop WordPress appending `-2` to the end of my url after i change it
- Removing Parent Page(s) from Permalink
- Removing the redirect after changing a page’s slug
- How to display a public profile page for registered users with custom slug?
- Page begins with number, WordPress adds 2
- Permalink Issues by Installing WordPress in Subdirectory / Subfolder
- Include Taxonomy slug in post url
- Nice RSS Feed URLs for each custom post type
- How to set permalink to fetch all children custom posts with parent post in wordpress?
- Rewrite url / permalink for default archive – yearly / monthly
- Should I use relative or absolute urls when pointing to internal pages
- removed index.php now all pages 404
- permalinks has -2 with post name structure. why?
- How can I change permalinks to use a different domain and path from where the blog is hosted?
- Gutenberg Editor: dynamicaly change slug field with an ACF field
- Permalinks all messed up, I am helpless [closed]
- Child pages with same slug
- Permalinks, Rewrites, Get Variables, Oh My!
- Can’t get rewrite rules working
- permalink changed, now getting 404 for every pages
- How to write correct add_rewrite_rule in WordPress for more than one taxonomy in one rule?
- When is it a good idea to build a permalink structure from scratch?
- How to reset canonical URLs / fix redirect loop
- Permalinks not working Apache + CentOS 7
- Trailing slash at the end of permalink loads faster / better SEO?
- How to show the homepage on a different url, like site.com/blog instead of site.com?
- Post incorrectly displaying as page
- wp-admin post.php JavaScript Links Not Working
- why does my url not update after migration?
- Dynamically create Permalinks for uploaded files?
- Get new WordPress slug from old wordpress slug
- Moved page (new parent) loads properly using obsolete URI. Why?
- Rewrite rule for a query string
- Is it possible for a custom post type and sub pages of a page with the same slug as the custom post type to share a slug?
- Why is page/2/ not working?
- Removing leading zeros from custom permalink structure
- Permalinks stopped working – NO update, mod_rewrite enabled, .htaccess not touched
- A link to a page including an anchor doesn’t go to that anchor – URL gets changed
- Default permalink changes
- Changing permalink name redirects to another template?
- How can I emulate permalink behaviour on static pages
- add_query_vars and canonical links
- Changing the permlink and SEO
- whats the mistake → href=”get_permalink() [closed]
- Media/attachment urls don’t redirect with fake URL structure
- Remove a link from a page ID used within an array [closed]
- How can I link to the author’s page
- WordPress pages and posts are redirecting to server IP address instead of domain URL [closed]
- Passing variable as permalink URL
- “set_front” => false on custom post type breaks wp_list_categories links [closed]
- Customizing a permalink
- Moving blog and maintaining current permalinks
- All pages load the home page if pretty permalinks are used
- where can i see wordpress automatic redirect History
- WordPress keeps removing query var from the URL
- Homepage template and url changed?
- How can I access to the same post-type “page” from multiple different urls?
- Multiple URL rewrite rules and get every prams
- Added .html to Woocommerce permalink but pagination don’t work!
- Subpages getting a 404 error after changing Parent page URL
- Automatisation permalinks for each making of new page
- Updating wordpress permalinks to use https://
- Remove/hide a specify category-name from the url
- Page permalink ending in “-2”
- rewrites and custom links in page need help with add_rewrite_rule
- Change the permalinks structure
- How to create an IIS7 re-write rule for a single category
- Although rewrite engine is on, I get 404 not found on every page
- how to change permalinks from id to name of a particular location
- Find which Permalink structure is the best
- Permalinks of New Pages and their Parents
- Leverage permalinks with AJAX
- Styles are not loading when changing permalink to %postname%?
- Getting the Posts’ permalinks from XLMRPC
- WordPress: Permalinks link to old names
- Creating complex URLs with WordPress permalink structure
- Permalinks is not working in my wordpress setup
- Use .htaccess to redirect homepage to its permalink
- -2 generated in permalink postname [duplicate]
- Pages resolve at different URLs (different capitalizations)
- Permalink settings are stuck on https, will not update to http