Guest User

Untitled

a guest
Feb 22nd, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. function change_event_slug_on_save( $post_id ) {
  2. if ( ! wp_is_post_revision( $post_id ) && tribe_is_event($post_id) ) {
  3. $post = get_post($post_id);
  4. $slug = sanitize_title($post->post_title);
  5. $newslug = $slug . '-' . tribe_get_start_date( $post_id, false, 'j F Y' );
  6. if ($post->post_name !== $newslug) {
  7. // verify post is not a revision, and an event
  8. // unhook this function to prevent infinite looping
  9. remove_action( 'save_post', 'change_event_slug_on_save' );
  10. // update the post slug
  11. wp_update_post( array(
  12. 'ID' => $post_id,
  13. 'post_name' => $newslug
  14. ));
  15. // re-hook this function
  16. add_action( 'save_post', 'change_event_slug_on_save', 10, 1 );
  17. }
  18. }
  19. }
  20.  
  21. add_action( 'save_post', 'change_event_slug_on_save', 10, 1 );
Add Comment
Please, Sign In to add comment