Last active
May 17, 2024 03:13
-
-
Save mennwebs/8035f5acf6b38d457a3beb44ef184e48 to your computer and use it in GitHub Desktop.
WordPress - Event Post Type Slug from date
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 /* 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