我正在编写一个在wordpress中插入帖子的外部工具(我正在使用wordpress函数)。我还阅读了以下讨论:wp_insert_post does not write my post_name
但我的问题有点不同。我插入了post,但post\\u name为空。代码为:
// Create post object
$my_post = array(
\'post_title\' => $article_title,
\'post_name\' => $article_title,
\'post_content\' => $article_content,
\'post_status\' => \'pending\',
\'post_author\' => 1,
\'post_category\' => array(8,39)
);
// Insert the post into the database
wp_insert_post( $my_post );
我尝试了使用和不使用post\\u名称,但结果没有改变。我也尝试过:$post_ID = (int) $wpdb->insert_id;
$post_name = wp_unique_post_slug($article_title, $post_ID, $post_status, $post_type, $post_parent);
$where = array( \'ID\' => $post_ID );
$wpdb->update( $wpdb->posts, array( \'post_name\' => $post_name ), $where );
但是,例如,插入post\\u名称,但:不是唯一的,例如“Test”没有变成“Test”,我做错了什么?