首页 视频课程 WordPress开发文档文章格式类型与评论 完整投稿

完整投稿

2020-03-23 / 5878阅

WordPress使用wp_insert_post()函数插入文章,本文为大家讲解所有的参数。

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

常用的几个参数,例如标签、自定义字段、分类目录、分类法比较难懂。我这里给大家一个代码实例:

$post_data = array(
       'post_title' => $_POST['data']['title'],
       'post_content' => $_POST['data']['content'],
       'post_type' => 'answer', //默认的文章类型  post    ,比如 page
       'post_status'=>'publish',
       'tags_input' => array('我的表情'),   //(数组)标记名称,段或ID的数组。默认为空。
       'tax_input' => array(  //(数组)以分类名称命名的分类术语数组。默认为空。
              'answer_list'=>array($_POST['data']['term_id'])
       ),
       'meta_input' => array( //(数组)由后置元键键入的后置元值数组。默认为空。
              'qzl_title'=>'我的标题',
       ),
);
$re = wp_insert_post($post_data); 

阅读文章或者观看视频过程中有任何问题,请下方留言或者联系我Q248758228

大家谈论
    我的见解
    目录