hjaffer2001 hjaffer2001 -4 years ago 72
PHP Question

Comment not being posted with xml-rpc wp.newComment php

I have a code like this.


$client = new IXR_Client('');

$data = array(
'comment_post_ID' => 1,
'comment_author' => 'test_author',
'comment_author_email' => 'test@gmail.com',
'comment_author_url' => 'http://test.limewebs.com',
'comment_content' => 'Test Content',
'comment_type' => '',
'comment_parent' => 0,
'user_id' => 1,
'comment_author_IP' => '',
'comment_agent' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/2009042316 Firefox/3.0.10 (.NET CLR 3.5.30729)',
'comment_date' => $time,
'comment_approved' => 1,

if (!$client->query('wp.newComment','', 'username','password','12',$data)) {
die('An error occurred - '.$client->getErrorCode().":".$client->getErrorMessage());
$result = $client->wp_insert_comment($data);

In the above code, I get my comment posted to WordPress site, but the content(comment_content) is not getting posted.

Answer Source

Dude, remove all 'comment_' prefix to your array properties. Writing the WpAPI Class I dug deep in the heart of WP's XMLRPC. Parameters are always never in the order an normal person would put them. The names used are not consistent either. It's not a guessing game. Always look at the WP core code when not sure... [or use my Class ;)]

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download