How to use metaWeblog.getPost, metaWeblog.getRecentPosts and metaWeblog.deletePost

How to use metaWeblog.getPost, metaWeblog.getRecentPosts and metaWeblog.deletePost

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.

 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)
<?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 :

how to use metaWeblog.getRecentPosts return 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
<?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.
<?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.

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

%d bloggers like this: