2011-05-05 55 views

回答

24

POST_TITLE設置標題和POST_NAME設置蛞蝓。 所以:

// 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); 
+0

謝謝..其工作。 我不會注意到post_name .. – Andy 2011-05-06 09:15:34

+0

嗨,是否有可能將帖子ID添加到post_name的末尾,以便生成的slug看起來像「hello-world-123」,其中123是插入的帖子ID? – Anagio 2012-12-22 11:27:19

+0

這是我嘗試過的,但得到一個錯誤''post_name'=>'$ title'。''''''',' – Anagio 2012-12-22 11:29:15

相關問題