首页 视频课程 WordPress开发文档文章格式类型与评论 插入评论

插入评论

2020-11-01 / 6185阅

本视频需要登录以后才能播放

登录

WordPress可以使用代码插入评论,主要用于AJAX提交评论。或者采集文章评论,也可以是远程提交。代码负责把收到的信息插入到wordpress文章中。

我们是下面的函数来插入评论

$args = array(
       'comment_agent' => '',//(字符串)$comment_author提交评论时的HTTP用户代理。默认为空。
       'comment_approved' => '',//(int | string)评论是否已被批准。默认值1。
       'comment_author' => '',//(字符串)评论作者的名称。默认为空。
       'comment_author_email' => '',//(字符串)的电子邮件地址$comment_author。默认为空。
       'comment_author_IP' => '',//(字符串)的IP地址$comment_author。默认为空。
       'comment_author_url' => '',//(字符串)的URL地址$comment_author。默认为空。
       'comment_content' => '',//(字符串)评论的内容。默认为空。
       'comment_date' => '',//(字符串)提交评论的日期。要手动设置日期,$comment_date_gmt还必须指定。默认为当前时间。
       'comment_date_gmt' => '',//(字符串)注释在GMT时区中提交的日期。默认值为$comment_date网站的GMT时区。
       'comment_karma' => '',//(int)评论的业力。默认值0。
       'comment_parent' => '',//(int)此评论的父级的ID(如果有)。默认值0。
       'comment_post_ID' => '',//(int)与评论相关的帖子的ID(如果有)。默认值0。
       'comment_type' => '',//(字符串)注释类型。默认为空。
       'comment_meta' => '',//(数组)可选。要存储在新评论的commentmeta中的键/值对的数组。
       'user_id' => ''//
);
wp_insert_comment($args); 

实际使用的时候我们不一定需要所有的参数,就简单的评论需要文章ID和评论内容,其实文章ID都可以省略。

$args = array(
       'comment_author' => '悠然自学',//(字符串)评论作者的名称。默认为空。
       'comment_post_ID' => '257',//(int)被评论的文章ID。默认值0。
       'comment_content' => '257-47--悠然自学、乐在其中,演示评论',//(int)
);
wp_insert_comment($args); 

如果不是采集的内容,请把comment_approved设置为0,确保用户发表的评论需要审核,如无需审核,无用传递此参数。

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

大家谈论
    我的见解
    目录