How to set / slug POST permalink in wordpress using wp_insert_post

I am writing a simple script using wp_insert_post() to post a blog article. but one problem here, I want to make the header and slug of another URL.

How to do it?

eg:

Title: How to make your diet a success

Slug: 7-ways-to-make-succes-Diet

+8
wordpress permalinks slug
source share
1 answer

post_title sets the header, and post_name sets the pool. So:

 // Create post object $my_post = array( 'post_title' => 'How to make your diet success', 'post_name' => '7-ways-to-make-succes-Diet', 'post_content' => 'my content', 'post_status' => 'publish', 'post_author' => 1, 'post_category' => array(8,39) ); // Insert the post into the database wp_insert_post( $my_post ); 
+24
source share

All Articles