Continuing my article on Simple WordPress XMLRPC with IXR_Library Class, I will share about how to use metaWeblog.getPost, metaWeblog.getRecentPosts and metaWeblog.deletePost. I combine these three APIs in the article because it is easy to use and are rarely used.
Lets begin tutorial.
To using these wordpress API we need IXR_Library Class.
Table of Contents
metaWeblog.getRecentPosts
metaWeblog.getRecentPosts used to get data from the end of your blog posts, MetaWeblog.getRecentPosts will retrieve a list of recent posts. Parameters required
- int blogid : Not applicable for WordPress, can be any value and will be ignored.
- string username
- string password
- int numberOfPosts : Optional. (In my example i retrieve 3 recent posts)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php include "IXR_Library.php"; $XmlRpc_result = null; $url= 'http://your-url.com/xmlrpc.php'; $XmlRpc_client = new IXR_Client ($url); $params = array(1,'username','password',3); // will retrieve 3 of recent posts try{ $XmlRpc_result = $XmlRpc_client->query( 'metaWeblog.getRecentPosts',$params ); $data = $XmlRpc_client->getResponse(); print_r($data); } catch (Exception $e){ var_dump ( $e->getMessage ()); } ?> |
Result :
metaWeblog.getPost
MetaWeblog.getPost equal with metaWeblog.getRecentPosts, but metaWeblog.getPost only restore specific posts based postid. Here the metaWeblog.getPost parameters
- int postid
- string username
- string password
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php include "IXR_Library.php"; $XmlRpc_result = null; $url= 'http://example.com/xmlrpc.php'; $XmlRpc_client = new IXR_Client ($url); $params = array(54,'username','password'); // in my example postid = 54 try{ $XmlRpc_result = $XmlRpc_client->query( 'metaWeblog.getPost',$params ); $data = $XmlRpc_client->getResponse(); print_r($data); } catch (Exception $e){ var_dump ( $e->getMessage ()); } ?> |
metaWeblog.deletePost
Use for Delete an existing post. With metablog.deletePost will move the blog post to the trash. Parameter required is
- string appkey: Not applicable for WordPress, change with ” “.
- int postid
- string username
- string password
- bool publish: Will be ignored with false.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <?php include "IXR_Library.php"; $XmlRpc_result = null; $url= 'http://example.com/xmlrpc.php'; $XmlRpc_client = new IXR_Client ($url); $params = array('',1,'username','password',true); try{ $XmlRpc_result = $XmlRpc_client->query( 'metaWeblog.deletePost',$params ); $data = $XmlRpc_client->getResponse(); print_r($data); } catch (Exception $e){ var_dump ( $e->getMessage ()); } ?> |
Thus tutorial how to use the MetaWeblog API to wordpress, please read another tutorial using XMLRPC with MetaWeblog here.
Leave a Reply