首页 WordPress函数大全 wp_insert_post()

wp_insert_post()

2020-04-03 / 4438阅 / 悠然

如何你看完本文还不知道如何使用该函数,可以联系我定制视频教程,50元/个函数,学不会全额退款

功能

用户插入或者更新文章,传ID为更新文章,不传为插入文章

参数

 $post_data = array(
       'post_title' => $_POST['data']['title'],
       'post_content' => $_POST['data']['content'],
       'post_type' => 'answer', //默认的文章类型  post    ,比如 page
       'ID' => '',   //(int)文章ID。如果等于0以外的值,则具有该ID的文章将被更新。默认值0。
       'post_author' => '',   //(int)添加文章的用户的ID。默认值为当前用户ID。
       'post_date' => '',   //(字符串)发布日期。默认为当前时间。
       'post_date_gmt' => '',   //(字符串) GMT时区中的文章日期。默认值为$post_date。
       'post_content_filtered' => '',   //(字符串)过滤后的文章内容。默认为空。
       'post_excerpt' => '',   //(字符串)文章摘录。默认为空。
       'post_status' => '',   //(字符串)发布状态。默认为“草稿”。 publish已发布  future 定时   draft 草稿
       'comment_status' => '',   //(字符串)文章是否可以接受评论。接受“open”或“closed”。默认值为“ default_comment_status”选项的值。
       'ping_status' => '',   //(字符串)文章是否可以接受ping。接受“open”或“closed”。默认值为“ default_ping_status”选项的值。
       'post_password' => '',   //(字符串)访问文章的密码。默认为空。
       'post_name' => '',   //(字符串)文章名称。默认是创建新文章时经过清理的文章标题。
       'to_ping' => '',   //(字符串)空格或回车分隔的ping URL列表。默认为空。
       'pinged' => '',   //(字符串)已被ping通的URL的空格或回车分隔的列表。默认为空。
       'post_modified' => '',   //(字符串)上次修改文章的日期。默认为当前时间。
       'post_modified_gmt' => '',   //(字符串)在GMT时区中最后一次修改文章的日期。默认为当前时间。
       'post_parent' => '',   //(int)对其所属的文章进行设置(如果有)。默认值0。
       'menu_order' => '',   //(int)文章显示的顺序。默认为0。
       'post_mime_type' => '',   //(字符串)文章的mime类型。默认为空。
       'guid' => '',   //(字符串)用于引用文章的全局唯一ID。默认为空。
       'post_category' =>array(1,2),   //(数组)类别ID的数组。默认为'default_category'选项的值。
       'tags_input' => '',   //(数组)标记名称,段或ID的数组。默认为空。
       'tax_input' => '',   //(数组)以分类名称命名的分类术语数组。默认为空。
       'meta_input' => '',   //(数组)由后置元键键入的后置元值数组。默认为空。
);
$re = wp_insert_post($post_data);  
大家谈论
    我的见解