【发布时间】:2011-08-19 08:36:14
【问题描述】:
我正在使用wp_insert_post() 编写简单的脚本以在博客中发布文章。
但这里有一个问题,我想让 URL 的 Title 和 slug 不同。
如何做到这一点?
例如:
标题:如何让你的饮食成功
蛞蝓:7-ways-to-make-succes-Diet
【问题讨论】:
标签: wordpress slug permalinks
我正在使用wp_insert_post() 编写简单的脚本以在博客中发布文章。
但这里有一个问题,我想让 URL 的 Title 和 slug 不同。
如何做到这一点?
例如:
标题:如何让你的饮食成功
蛞蝓:7-ways-to-make-succes-Diet
【问题讨论】:
标签: wordpress slug permalinks
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' => '$title'.'-'$pid',
, 'post_name' => sanitize_title_with_dashes($title,'','save')