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’