Drafts Action Directory

WordPress - New Post

Posted by agiletortoise, Last update about 1 year ago

Create a new post on a WordPress blog using XML-RPC API through Drafts scripting. Additional options can be configured using parameters documented in Wordpress XML-RPC api docs. This example will create the post as a draft.



  • script

    // setup values to use in post
    let title = draft.processTemplate("[[title]]");
    let body = draft.processTemplate("[[body]]");
    // 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.newPost"
    let params = [
    	1, // blog_id, in most cases just use 1
    		"post_title": title,
    		"post_content": body
    let response = wp.runMethod(method, params);
    if (response.success) {
    	console.log("Response: " + JSON.stringify(response.params));
    	console.log("Error: " + response.error);
    	console.log("Create WordPress post id: " + response.params[0]);
    else {
    	console.log("HTTP Status: " + response.statusCode);
    	console.log("XML-RPC Fault: " + response.faultCode + ", " + response.error);


  • After Success Default
    Notification Info
    Log Level Info


Actions available in the Action Directory are uploaded by community members. Use appropriate caution reviewing downloaded actions before use.