8
我使用wp_insert_post()
編寫簡單腳本在blog中發佈文章。 但這裏有一個問題,我想製作標題和slu 012的URL不同。如何使用wp_insert_post在wordpress中設置POST永久鏈接/ slug
如何實現這一目標?
例如:
標題:如何讓你的飲食成功
彈頭:7-ways-to-make-succes-Diet
我使用wp_insert_post()
編寫簡單腳本在blog中發佈文章。 但這裏有一個問題,我想製作標題和slu 012的URL不同。如何使用wp_insert_post在wordpress中設置POST永久鏈接/ slug
如何實現這一目標?
例如:
標題:如何讓你的飲食成功
彈頭:7-ways-to-make-succes-Diet
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);
謝謝..其工作。 我不會注意到post_name .. – Andy 2011-05-06 09:15:34
嗨,是否有可能將帖子ID添加到post_name的末尾,以便生成的slug看起來像「hello-world-123」,其中123是插入的帖子ID? – Anagio 2012-12-22 11:27:19
這是我嘗試過的,但得到一個錯誤''post_name'=>'$ title'。''''''',' – Anagio 2012-12-22 11:29:15