1

Hello all happy holidays! :)

I'm trying to insert comments in my wordpress blog via the wp_insert_comment() function. It's for a plugin I'm trying to make.

I have this code in my header for testing. It works every time I refresh the page.

$agent = $_SERVER['HTTP_USER_AGENT'];

$data = array(
    'comment_post_ID' => 256,
    'comment_author' => 'Dave',
    'comment_author_email' => '[email protected]',
    '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);

It successfully inserts comments into the database.

The problem: Comments don't show via the Disqus comment system. I compared table rows and I noticed that user_agent differs.

Normal comments use for example, Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv...

and Disqus comments use Disqus/1.1(2.61):119598902 numbers are different for each comment.

Does anyone know how to insert comments with wp_insert_comment() when Disqus is enabled?

2 Answers 2

2

You need to add this parameters:

'comment_type' => '',

Try to use this code:

$agent = $_SERVER['HTTP_USER_AGENT'];
$data = array(
    'comment_post_ID' => 256,
    'comment_author' => 'Dave',
    'comment_author_email' => '[email protected]',
    '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);
Sign up to request clarification or add additional context in comments.

Comments

0

I don't think Disqus imports comments from the WordPress database in real-time. If you wanted it to appear in Disqus' database immediately, you'd need to insert it via the Disqus API.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.