首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WordPress动态页面结构

WordPress动态页面结构
EN

Stack Overflow用户
提问于 2013-12-31 16:47:16
回答 2查看 70关注 0票数 0

通常,我会转到仪表板来设置pages父属性。假设我正在动态地创建一个页面,所以它无法通过仪表板进行编辑,是否有一种以编程方式设置父属性的方法?

谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-12-31 16:51:47

您可以查看wp_insert_post()函数。它接受一个$post数组,您可以设置父ID.。

下面是一个例子:

代码语言:javascript
复制
// Create post object
$my_post = array(
  'post_title'    => 'My post',
  'post_content'  => 'This is my post.',
  'post_status'   => 'publish',
  'post_type'     => 'page',
  'post_author'   => 1,
  'post_parent'   => [ <post ID> ], // Sets the parent of the new post, if any. Default 0.
  'post_category' => array(8,39)
);

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

我希望它能帮上忙!-用例子更新

票数 1
EN

Stack Overflow用户

发布于 2013-12-31 16:51:11

检查wp_insert_post - post

您可以通过post_parent参数设置post父级。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20860542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档