Skip to content

Instantly share code, notes, and snippets.

@mennwebs
Last active May 17, 2024 03:13
Show Gist options
  • Save mennwebs/8035f5acf6b38d457a3beb44ef184e48 to your computer and use it in GitHub Desktop.
Save mennwebs/8035f5acf6b38d457a3beb44ef184e48 to your computer and use it in GitHub Desktop.
WordPress - Event Post Type Slug from date
<?php /* EVENT SLUG FROM DATE*/
function event_slug($post_id, $post, $update)
{
if (get_field('date', $post_id)) {
$date = get_field('date', $post_id);
$slug = date('ymd', strtotime($date));
if ($post->post_name != $slug) {
remove_action('save_post_event', 'event_slug', 10, 3);
wp_update_post([
'ID' => $post_id,
'post_name' => $slug
]);
add_action('save_post_event', 'event_slug', 10, 3);
}
}
}
add_action('save_post_event', 'event_slug', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment