Last active
October 20, 2016 00:20
-
-
Save jacquesletesson/def518c8b0e9a8c85fa1 to your computer and use it in GitHub Desktop.
The Event Calendar - Permalink with starting date injected automatically.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Add this to your function.php | |
function please_update_slug( $data, $postarr ) { | |
if($data['post_type'] == 'tribe_events') { | |
if ( !in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) { | |
$post_id = $postarr['ID']; | |
$value = $_POST["EventStartDate"]; | |
$date = new DateTime($value); | |
$data['post_name'] = sanitize_title( $data['post_title'] . '-' . $date->format('d-m-Y')); | |
} | |
} | |
return $data; | |
} | |
add_filter( 'wp_insert_post_data', 'please_update_slug', 99, 2 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great, when using the importer though you have to use $postarr['EventStartDate'], which also works when saving regularly