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
- Removing /wp in Permalink URL of subdomain led to inaccessibility to WP Dashboard
- How do I disable the changing of the permalink for published posts (for non-admin)?
- WordPress homepage shows default theme after migration – logged-out users see different content
- Is it possible to get a page link from its slug?
- Need help with add_rewrite_rule
- After server migration only the homepage works
- Is it possible to reuse wp.media.editor Modal for dialogs other than media
- remove “index.php” from permalinks
- where is permalink info stored in database?
- Changing permalinks gives me 404 errors on nginx
- How do I add /blog/ as a prefix to permalink structure for blog posts, tag pages, etc.?
- Change media item permalink
- Get Permalink without domain (i.e. get relative permalink) [duplicate]
- How does WordPress create URLs that Apache knows about?
- Strange permalink issue: can’t rename /company-2/ to /company/
- Passing and retrieving query vars in wordpress
- Get the current page URL (including pagination)
- Stop WordPress appending `-2` to the end of my url after i change it
- Get default permalink structure from pretty URL’s
- How to get permalink and title from post ID?
- Why is “/page/2/” not working?
- WordPress Permalinks not working in Apache2 Ubuntu 14.04
- Performance of my permalink structure?
- Permalink format: singular or plural
- What is the difference between get_post_permalink and get_permalink?
- WordPress matching URLs with trailing tildes
- Get current URL (permalink) without /page/{pagenum}/
- How does WordPress handle permalinks?
- Pretty permalinks for search results with extra query var
- Get page permalink without wpurl
- How can I get the privacy policy page?
- Can I use REST-API on plain permalink format?
- WordPress slug issue with non-latin characters
- Rewrite Rule for Multilingual Website, Like qTranslate?
- How to get pretty URLs with add_query_arg in permalinks
- What is the best permalink structure for SEO?
- Change author permalink
- Creating custom permalink structure for languages
- Hide permalink and preview button and link on custom post
- Custom post type permalink endpoint
- How can I make Capital letter ( upper-case ) permalinks?
- How can I reverse engineer a Permalink to Find the Page?
- Mapping Domains to Permalinks (not multisite)
- How to remove dates from existing permalinks?
- How do I set a custom base URL for standard posts?
- Removing Parent Page(s) from Permalink
- Why permalinks work with /index.php/%postname% but not with just %postname%?
- Using TinyMce with textareas in meta boxes on custom post types
- Setting up WordPress with Custom Permalinks and no .htaccess File?
- Getting the Site URL Including the Front Base
- Does WordPress Change the .htaccess File When Updating?
- Using $_GET variables in the URL?
- Removing the redirect after changing a page’s slug
- How to display a public profile page for registered users with custom slug?
- Removing leading zeros from custom permalink structure
- Must slugs be unique?
- Setting 404 page in Nginx
- How to get the clean permalink in a draft?
- How to use relative links on my pages?
- How does wordpress keep track of post id when post id is not used in permalinks?
- How to filter to output of the get_permalink() function
- Stop WordPress from reserving slugs for media items?
- Including category-base in a post permalink results in 404
- How to change ‘with_front” key from an existing custom post type?
- js error on post editing page
- Change slug on post creation
- Does WordPress automatically do 301 redirect if I change permalink
- How can I store page ID in a post instead of other selected permalink?
- API to trigger prompt on leaving page
- WordPress Permalink changes to question mark (?) in URL
- WordPress thinks my custom route is a 404
- Prevent WordPress from abbreviating-long-slugs…-in-the-admin
- Adding another word in front of post url
- Permalink with sub-sub-category and post name
- Post type child of another post type
- Permalink not working for page without title
- Remove index.php in permalink structure on IIS server
- What is the difference between get_permalink vs get_the_permalink?
- Page begins with number, WordPress adds 2
- Move WordPress to subdirectory, keep ALL URLs
- How would I create a different permalink structure for pages and posts?