首页 文章

Wordpress通过wp_insert_comment()插入注释

提问于
浏览
0

各位节日快乐! :)

我正试图通过 wp_insert_comment() 函数在我的wordpress博客中插入评论 . 它正在努力做到.749392_

我在我的 Headers 中有这个代码用于测试 . 它每次刷新页面时都有效 .

$agent = $_SERVER['HTTP_USER_AGENT'];

$data = array(
    'comment_post_ID' => 256,
    'comment_author' => 'Dave',
    'comment_author_email' => 'dave@domain.com',
    'comment_author_url' => 'http://www.someiste.com',
    'comment_content' => 'Lorem ipsum dolor sit amet...',
    'comment_author_IP' => '127.3.1.1',
    'comment_agent' => $agent,
    'comment_date' => date('Y-m-d H:i:s'),
    'comment_date_gmt' => date('Y-m-d H:i:s'),
    'comment_approved' => 1,
);

$comment_id = wp_insert_comment($data);

它成功地将注释插入数据库 .

问题:评论不会通过Disqus评论系统显示 . 我比较了表行,我注意到user_agent不同 .

正常注释使用例如 Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv...

和评论使用 Disqus/1.1(2.61):119598902 数字是不同的每个评论 .

当启用Disqus时,有没有人知道如何使用 wp_insert_comment() 插入注释?

2 回答

  • 0

    我马上要't think Disqus imports comments from the WordPress database in real-time. If you wanted it to appear in Disqus'数据库,你需要通过the Disqus API插入它 .

  • 1

    您需要添加以下参数:

    'comment_type' => '',
    

    尝试使用此代码:

    $agent = $_SERVER['HTTP_USER_AGENT'];
    $data = array(
        'comment_post_ID' => 256,
        'comment_author' => 'Dave',
        'comment_author_email' => 'dave@domain.com',
        'comment_author_url' => 'http://www.someiste.com',
        'comment_content' => 'Lorem ipsum dolor sit amet...',
        'comment_author_IP' => '127.3.1.1',
        'comment_agent' => $agent,
        'comment_type'  => '',
        'comment_date' => date('Y-m-d H:i:s'),
        'comment_date_gmt' => date('Y-m-d H:i:s'),
        'comment_approved' => 1,
    

    );

    $comment_id = wp_insert_comment($data);
    

相关问题