I didn't find any xmlrpc method call to do it in WordPress codex. I can get all the posts via metaWeblog.getRecentPosts and extract IDs, but I didn't exactly know the count of the posts in blog.
There isn't an XML-RPC method to get all posts, mostly because that could lead to significant performance issues (imaging a blog with 5,000 posts and high traffic ... trying to parse a list of everything would cause some serious server lag).
The closest you can get with stock WordPress methods would be with the getRecentPosts
calls: blogger.getRecentPosts
and metaWeblog.getRecentPosts
(the MetaWeblog call is actually just an alias to the Blogger call).
That said, you can create your own method that returns either a count of published posts or a list of the IDs of the published posts. Just create a quick plug-in to hook into the XML-RPC system to add your endpoint and method:
function xml_add_method( $methods ) {
$methods['myNamespace.postCount'] = 'get_post_count';
$methods['myNamespace.postIDList'] = 'get_post_id_list';
return $methods;
}
add_filter( 'xmlrpc_methods', 'xml_add_method' );
That code block will add two new calls to your XML-RPC system, myNamespace.postCount
and myNamespace.postIDList
. You can call these remotely to return a count of published posts and a list of published post IDs, respectively.
You also need to define the PHP functions that will handle the request - all the XML-RPC system does it route remote requests to internal PHP functions that return data:
function get_post_count( $args ) {
global $wpdb;
... code that retrieves the total count of published posts from the database ...
return $count;
}
function get_post_id_list( $args ) {
global $wpdb;
... code that retrieves a list of published posts from the database ...
return $postlist;
}
That's it. Pull all the code together into a custom plug-in, place it in your site, activate it, and you can now get a count of published posts or a list of published post IDs via XML-RPC.