wordpress change slug programmatically

Solutions on MaxInterview for wordpress change slug programmatically by the best coders in the world

showing results for - "wordpress change slug programmatically"
Tidiane
30 Jun 2018
1// Create post object
2$my_post = array(
3     'post_title' => 'How to make your diet success',
4     'post_name' => '7-ways-to-make-succes-Diet', //This is what set
5     'post_content' => 'my content',
6     'post_status' => 'publish',
7     'post_author' => 1,
8     'post_category' => array(8,39)
9  );
10
11// Insert the post into the database
12$post_id = wp_insert_post( $my_post );
13
14//For updates use this:
15wp_update_post([
16  "post_name" => "new-slug",
17  "ID" => $post_id,
18]);
19