WordPress函数:wp_insert_post 添加投稿功能

追格官方小助手/ 2022年05月27日/ WordPress/ 浏览 2202

如何为WordPress主题、WordPress小程序添加投稿功能?只需要使用 wp_insert_post 函数添加文章,并设置为待审核状态。


编辑文章也可以使用这个函数,只需要在传入的文章中包含文章ID就可以。


最重要的参数就是文章标题和文章内容,其他的文章属性该函数都提供了默认值。


wp_insert_post(array(
        'post_title' => '文章标题',
        'post_content' => '文章内容',
        'post_status' => 'pending' // 设置为待审核
))


其他参数详解:


'ID'(int)

文章ID。如果等于0以外的值,则将更新具有该ID的文章。默认值0。


'post_author'(int)

发布文章的用户的ID。默认值是当前用户ID。


'post_date'(string)

发布日期。默认值为当前时间。


'post_date_gmt'(string)

在GMT时区中发布的日期。默认值为$post_date。


'post_content'(string)

文章内容。默认为空。


'post_content_filtered'(string)

筛选后的文章内容。默认为空。


'post_title'(string)

文章标题。默认为空。


'post_excerpt'(string)

文章摘录。默认为空。


'post_status'(string)

文章状态。默认“草稿”。


'post_type'(string)

文章类型。默认“post”。


'comment_status'(string)

文章是否可以接受评论。接受“打开”或“关闭”。Default是“default_comment_status”选项的值。


'ping_status'(string)

post是否可以接受ping。接受“打开”或“关闭”。Default是“default_ping_status”选项的值。


'post_password'(string)

访问文章的密码。默认为空。


'post_name'(string)

职位名称。默认值是创建新文章时经过清理的文章标题。


'to_ping'(string)

空格或回车符将URL的分隔列表返回给ping。默认为空。


'pinged'(string)

空格或回车分隔已ping的URL列表。默认为空。


'post_modified'(string)

上次修改文章的日期。默认值为当前时间。


'post_modified_gmt'(string)

在GMT时区中最后一次修改文章的日期。默认值为当前时间。


'post_parent'(int)

为其所属的文章设置此选项(如果有)。默认值0。


'menu_order'(int)

文章的显示顺序。默认值0。


'post_mime_type'(string)

文章的mime类型。默认为空。


'guid'(string)

引用文章的全局唯一ID。默认为空。


'import_id'(int)

插入新文章时要使用的文章ID。如果指定,则不能与任何现有的文章ID匹配。默认值为0。


'post_category'(int[])

类别ID的数组。默认为“default_category”选项的值。


'tags_input'(array)

标记名、slug或id的数组。默认为空。


发表评论

暂无评论,抢个沙发...

客服 工单