Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

XML-RPC/wp.getComments

wp.getComments

Get data on multiple comments.

Availability

WordPress 2.7+

Parameters

  • (string) blog_id
  • (string) username
  • (string) password
  • (struct) filter [optional]
    • (string) status (approve, hold, spam) [optional]
    • (int) post_id [optional]
    • (int) number [optional - default: 10]
    • (int) offset [optional]

wp.getComments will return comments from newest to oldest. If you don't provide a filter['number'] value then it will limit the response to 10. These parameters can be used in combination, for instance to get up to 100 (filter['number'] = 100) of the spam comments (filter['status'] = 'spam') for a specific post (filter['post_id'] = 1 ).

Response

  • (array)
    • (dateTime.iso8601) date_created_gmt
    • (int) user_id
    • (int) comment_id
    • (int) parent
    • (string) status (approve, hold, spam)
    • (string) content
    • (string) link
    • (int) post_id
    • (string) post_title
    • (string) author
    • (string) author_url
    • (string) author_email
    • (string) author_ip
    • (string) type (<empty>, trackback, pingback)

Each array item is the same as the result of an XML-RPC/wp.getComment call.

The date_created_gmt field is always the GMT date, even if no time zone information is present. An empty type field indicates a regular comment.

Example Request


<?xml version="1.0"?>
<methodCall>
  <methodName>wp.getComments</methodName>
  <params>
    <param>
      <value>
        <string>1</string>
      </value>
    </param>
    <param>
      <value>
        <string>xmlrpc-example</string>
      </value>
    </param>
    <param>
      <value>
        <string>example-password</string>
      </value>
    </param>
    <param>
      <value>
        <struct>
          <member>
            <name>post_id</name>
            <value>
              <int>41</int>
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>

Example Response


<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
      <value>
        <array>
          <data>
            <value>
              <struct>
                <member>
                  <name>date_created_gmt</name>
                  <value>
                    <dateTime.iso8601>20081121T02:54:08</dateTime.iso8601>
                  </value>
                </member>
                <member>
                  <name>user_id</name>
                  <value>
                    <string>1</string>
                  </value>
                </member>
                <member>
                  <name>comment_id</name>
                  <value>
                    <string>8</string>
                  </value>
                </member>
                <member>
                  <name>parent</name>
                  <value>
                    <string>0</string>
                  </value>
                </member>
                <member>
                  <name>status</name>
                  <value>
                    <string>approve</string>
                  </value>
                </member>
                <member>
                  <name>content</name>
                  <value>
                    <string>Need more comments.</string>
                  </value>
                </member>
                <member>
                  <name>link</name>
                  <value>
                    <string>http://example.com/?p=41&cpage=1#comment-8</string>
                  </value>
                </member>
                <member>
                  <name>post_id</name>
                  <value>
                    <string>41</string>
                  </value>
                </member>
                <member>
                  <name>post_title</name>
                  <value>
                    <string>This is a test post</string>
                  </value>
                </member>
                <member>
                  <name>author</name>
                  <value>
                    <string>admin</string>
                  </value>
                </member>
                <member>
                  <name>author_url</name>
                  <value>
                    <string>http://example.com/</string>
                  </value>
                </member>
                <member>
                  <name>author_email</name>
                  <value>
                    <string>example@example.com</string>
                  </value>
                </member>
                <member>
                  <name>author_ip</name>
                  <value>
                    <string>::1</string>
                  </value>
                </member>
                <member>
                  <name>type</name>
                  <value>
                    <string/>
                  </value>
                </member>
              </struct>
            </value>
            <value>
              <struct>
                <member>
                  <name>date_created_gmt</name>
                  <value>
                    <dateTime.iso8601>20081120T23:49:42</dateTime.iso8601>
                  </value>
                </member>
                <member>
                  <name>user_id</name>
                  <value>
                    <string>1</string>
                  </value>
                </member>
                <member>
                  <name>comment_id</name>
                  <value>
                    <string>7</string>
                  </value>
                </member>
                <member>
                  <name>parent</name>
                  <value>
                    <string>0</string>
                  </value>
                </member>
                <member>
                  <name>status</name>
                  <value>
                    <string>approve</string>
                  </value>
                </member>
                <member>
                  <name>content</name>
                  <value>
                    <string>Yet another comment.</string>
                  </value>
                </member>
                <member>
                  <name>link</name>
                  <value>
                    <string>http://example.com/?p=41&cpage=1#comment-7</string>
                  </value>
                </member>
                <member>
                  <name>post_id</name>
                  <value>
                    <string>41</string>
                  </value>
                </member>
                <member>
                  <name>post_title</name>
                  <value>
                    <string>This is a test post</string>
                  </value>
                </member>
                <member>
                  <name>author</name>
                  <value>
                    <string>admin</string>
                  </value>
                </member>
                <member>
                  <name>author_url</name>
                  <value>
                    <string>http://example.com/</string>
                  </value>
                </member>
                <member>
                  <name>author_email</name>
                  <value>
                    <string>example@example.com</string>
                  </value>
                </member>
                <member>
                  <name>author_ip</name>
                  <value>
                    <string>::1</string>
                  </value>
                </member>
                <member>
                  <name>type</name>
                  <value>
                    <string/>
                  </value>
                </member>
              </struct>
            </value>
          </data>
        </array>
      </value>
    </param>
  </params>
</methodResponse>

PHP Example


require "./IXR_Library.inc.php";

$rpc = new IXR_Client( "http://example.com/xmlrpc.php" );
$status = $rpc->query(
    "wp.getComments",   // method name
    "1",                // blog id
    "xmlrpc-example",   // username
    "example-password", // password
    array(
        "post_id"   => 41
    )
);

if( !$status ) {
    print "Error ( " . $rpc->getErrorCode( ) . " ) : ";
    print $rpc->getErrorMessage( ) . "\n";
    exit;
}

$comment = $rpc->getResponse( );
print_r( $comment );