Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function change_event_slug_on_save( $post_id ) {
- if ( ! wp_is_post_revision( $post_id ) && tribe_is_event($post_id) ) {
- $post = get_post($post_id);
- $slug = sanitize_title($post->post_title);
- $newslug = $slug . '-' . tribe_get_start_date( $post_id, false, 'j F Y' );
- if ($post->post_name !== $newslug) {
- // verify post is not a revision, and an event
- // unhook this function to prevent infinite looping
- remove_action( 'save_post', 'change_event_slug_on_save' );
- // update the post slug
- wp_update_post( array(
- 'ID' => $post_id,
- 'post_name' => $newslug
- ));
- // re-hook this function
- add_action( 'save_post', 'change_event_slug_on_save', 10, 1 );
- }
- }
- }
- add_action( 'save_post', 'change_event_slug_on_save', 10, 1 );
Add Comment
Please, Sign In to add comment