WordPress - Get Recent Posts

Posted by agiletortoise, Last update over 5 years ago

Use WordPress API to retrieve recent posts from a WordPress blog and make a list of titles and links. Meant as an example only. More advanced options are available via additional parameters as documented in WordPress XML-RPC API docs.


  • script

    // create credentials for site
    let cred = Credential.createWithHostUsernamePassword("WordPress", "WordPress credentials. Include full URL (with http://) of the home page of your WordPress site in the host field.");
    // create WordPress object and make request
    let wp = WordPress.create(cred.getValue("host"), 1, "", "");
    let method = "wp.getPosts"
    let params = [
    	1, // blog_id, in most cases just use 1
    let response = wp.runMethod(method, params);
    if (response.success) {
    	// I should have an array of post objects in first param
    	let s = [];
    	let posts = response.params[0];
    	for (let post of posts) {
    		s.push(`- ${post.post_title} [link](${})`);
    	let d = Draft.create();
    	d.content = s.join("\n");
    else {
    	console.log("HTTP Status: " + response.statusCode);
    	console.log("XML-RPC Fault: " + response.faultCode + ", " + response.error);;


  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.