Tagged: permalink
- This topic has 1 reply, 2 voices, and was last updated 4 years, 11 months ago by
ccarey75.
Viewing 1 reply thread
-
AuthorPosts
-
-
March 13, 2017 at 3:42 pm #7833
titidodoParticipantHi everybody,
i’m using Piklist for a CPT and i want to change the permalink structure. Right now the post_name as part of the url is generated out of the post_title, but i want it to be generated out of a custom (piklist) field. I edited the permalink manually for existing posts, but when i save and then edit and update the post, the permalink is the old one generated from the post_title.
Can you help me solving this problem?
Thanks in advance!
-
March 15, 2017 at 6:35 am #7835
ccarey75ParticipantYou want the save_post hook
https://codex.wordpress.org/Plugin_API/Action_Reference/save_postadd_action( 'save_post', 'my_save_post', 11, 2 ); function my_save_post($post_id, $post){ //if it is just a revision don't worry about it if (wp_is_post_revision($post_id)) return false; //if the post is an auto-draft we don't want to do anything either if($post->post_status != 'auto-draft' ){ // unhook this function so it doesn't loop infinitely remove_action('save_post', 'my_save_post' ); //this is where it happens -- update the post and change the post_name/slug to whatever you want wp_update_post(array('ID' => $post_id, 'post_name' => YOUR_SLUG_HERE ); //re-hook this function add_action('save_post', 'my_save_post' ); } }
-
-
AuthorPosts
Viewing 1 reply thread
- You must be logged in to reply to this topic.