Retrieve posts from WordPress remotely with XMLRPC and PHP

Retrieve posts from WordPress remotely with XMLRPC and PHP

Spread the love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

For the sake of this exercise, I am assuming that you have a clear understanding of what XML-RPC is. If not, read more about it here. I am also assuming that XML-RPC is enabled on your wordpress blog and you have the required IXR_Library.php.inc downloaded from here.

The code below is self-explanatory.

debug = true; // Set it to fase in Production Environment 
 
// Create the client object 
$client = new IXR_Client('Your Blog URL/xmlrpc.php'); 
$username = "USERNAME"; 
$password = "PASSWORD"; 
 
$params = array(0,$username,$password,20); // Last Parameter tells how many posts to fetch 
 
// Run a query To Read Posts From WordPress 
if (!$client->query('metaWeblog.getRecentPosts', $params)) { 
  die('Something went wrong - '.$client->getErrorCode().' : '.$client->getErrorMessage()); 
} 
 
$myresponse = $client->getResponse(); 

Once you have retrieved the post, you can loop them and display them in a table or process them the way you want it.

No votes yet.
Please wait...
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Related Post