如何使用wp_insert_post在wordpress中设置POST永久链接/段 [英] How to Set POST permalink/slug in wordpress using wp_insert_post

查看:56
本文介绍了如何使用wp_insert_post在wordpress中设置POST永久链接/段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用wp_insert_post()编写简单的脚本以在博客中发布文章. 但是这里有一个问题,我想使URL的 Title slug 不同.

I m writing simple script using wp_insert_post() to post article in blog. but one problem here, I want to make Title and slug of an URL different.

如何实现?

例如:

标题:如何使饮食成功

插头:7-ways-to-make-succes-Diet

推荐答案

post_title 设置标题,而 post_name 设置标签. 所以:

post_title sets the title, and post_name sets the slug. So:

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

这篇关于如何使用wp_insert_post在wordpress中设置POST永久链接/段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆