Last active
October 7, 2023 00:03
-
-
Save hauge75/9cdceb15c55c7738f7afa8170089ce03 to your computer and use it in GitHub Desktop.
Create random slug for custom post
This file contains 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
// Create random slug for custom post | |
function func_update_post_name( $post_id, $post ){ | |
if ( 'post-type-slug' == $post->post_type ) { | |
remove_action( 'save_post', 'func_update_post_name',30,2 ); | |
// update the post slug | |
wp_update_post( array( | |
'ID' => $post_id, | |
'post_name' => uniqid() | |
)); | |
add_action( 'save_post', 'func_update_post_name', 30, 2 ); | |
} | |
} | |
add_action( 'save_post', 'func_update_post_name', 30, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment