📜  wordpress 以编程方式更改 slug - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:02.790000             🧑  作者: Mango

代码示例1
// Create post object
$my_post = array(
     'post_title' => 'How to make your diet success',
     'post_name' => '7-ways-to-make-succes-Diet', //This is what set
     'post_content' => 'my content',
     'post_status' => 'publish',
     'post_author' => 1,
     'post_category' => array(8,39)
  );

// Insert the post into the database
$post_id = wp_insert_post( $my_post );

//For updates use this:
wp_update_post([
  "post_name" => "new-slug",
  "ID" => $post_id,
]);