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