常用函数-wp_update_post()

0条评论

常用函数-wp_update_post()

说明

该函数更新数据库中的文章。如希望函数正常运行,需传递将被更新的文章编号。

用法

<?php wp_update_post( $post ); ?>

示例

调用wp_update_post( )前需创建一个数组以传递必要元素。与 wp_insert_post()不同的是,这里只需要传递将更新的文章编号和元素。元素名称应与数据库中名称相匹配。

// Update post 37    
  $my_post = array();    
  $my_post['ID'] = 37;    
  $my_post['post_content'] = 'This is the updated content.';    

// Update the post into the database    
  wp_update_post( $my_post );  

类别

需要将类别作为整数数组传递,该数组应与数据库中的类别编号相匹配。即使文章只属于某一项类别,情况也应如此。

参数

$post

(数组)(可选)能表示可组成文章元素的对象。这些元素与数据库wp_posts表格中的纵列名称应一一对应。可以不填充ID(编号)字段,这样的话使用该函数几乎没有任何意义。

默认值:一个空数组

返回的值

若文章成功加入数据库,返回文章编号。否则返回0.

相关资源

wp_insert_post()

发表新评论

此内容将保密,不会被其他人看见。
  • 自动将网址与电子邮件地址转变为链接。
  • 允许HTML标签:<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • 自动断行和分段。

更多关於格式化选项的信息

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.