Using WordPress with Drafts

wordpress-logo

Drafts (v5.4 or greater) can be used with the WordPress blogging and content management system via integration with the WordPress XML-RPC API.

The XML-RPC API is available, and enabled by default, in WordPress version 3.5 or greater, but its availability, and limits on its use, may vary by where your WordPress site is hosted. It is highly recommend you use secure connections (https) to connect to your site using XML-RPC.

Posting to WordPress

Drafts provides a WordPress action step which allows creation and publishing of posts on a WordPress site. Example action:

This example posts to a WordPress blog in “Draft” status (to be published in the web interface later), using the first line of the title as the title of the post, and remaining text as the content.

This basic example can be modified to control post status, automatically assign categories, tags and even custom fields. The details of available options can be found in the action step documentation.

WordPress Credentials and Sites

The first time you run an action using a WordPress action step, you will be asked for details required to connect to your site. These include the host name of the home page of the WordPress site, and your username and password. These will be stored for future use with the action.

Be sure to enter the full URL to the home page of the WordPress site when prompted. This includes the “http://” or “https://” the host name and partial path if the site is hosted in a sub-directory, like: “https://mysite.com/blog/”.

If you only post to one WordPress site, no additional configuration is needed. If you wish to have actions which post to different WordPress sites, configure a unique value in the “Credential Identifier” field of the WordPress action step. All WordPress action steps with the same “Credential Identifier” will share the same login. This value can be anything, but using something like the host name of the site for easy identification is recommended.

wordpress-credentials

To reset credentials and login again, visit Settings > Credentials and “Forget” the WordPress credentials. Read more about Credentials.

Using the WordPress app share extension

WordPress also offers their own WordPress iOS app which can be used to post to WordPress.com of self-hosted WordPress blogs. The app offers a share extension, so if it is installed an configured on your device, it can be used via the Drafts “Share” action and the system share sheet. This approach is less automated, but is often a good choice if you want to make some selections of categories, tags, published status, etc., on the fly when you publish.

Scripting and the XML-RPC API

Drafts provides a WordPress scripting object which can be used to make direct requests to any methods available in the WordPress XML-RPC API. The object provides several convenience methods to fetch taxonomy information, etc., and also a runMethod function to call any method available in the API.

Using scripting, WordPress posts and taxonomy information can be queried, downloaded, updated, existing posts can be imports and more.

This wrapper handles the XML part of XML-RPC, making it easy to work with the WordPress API in Javascript, but is an advanced topic. For details, visit the scripting reference.

Example Scripted Actions:

Troubleshooting

If you have trouble posting to your WordPress blog, try the following:

  • If posting has never worked, ensure the site host, username and password are all correct and entered properly. You can forget the credentials in settings and re-run the action to re-enter them.
  • Check the action log after running a failed action for details on what error occurred.
  • Check with your hosting provider to be sure that the WordPress XML-RPC interface is allowed and enabled on WordPress installations on their service.
1 Like

I am having no luck trying to get this to work. I do have multiple blogs associated to my Wordpress account, each has its own URL. I’ve created a new user id and password specific to the blog I want to post to from Drafts and provided that as credentials and that doesn’t work either.

Basically, in Drafts the action indicates that it posted successfully but the item never appears in any of the Drafts sections of any of the blogs. The Drafts action log does not show an error. I’ve forgot and retried credentials several times.

Possible a couple of things are going on…most likely getting an error from your host. There is a bug that can report success on certain types of error using the step in 5.4 (fixed for 5.4.1). Try this scripted version and see what you are getting in the action log. It’s got more debugging info. Please open a ticket with the results (support@agiletortoise.com), we can better troubleshoot there.

Since wordpress updated to 5.0 and the new blocks editor this action still posts a draft but the markdown isn’t converted.

The default “Post to Wordpress” example above does not do Markdown conversion, it just sends the content of the draft. If the Markdown was converting for you in publishing before, it was likely being done at Wordpress’s end.

Honestly have not looked into changes in WP 5 to know how that affects input, but there’s likely someway to enable Markdown posts on the WP end still. Maybe someone else here is a Markdown user and will have more of an idea.

You can have Drafts convert the Markdown to HTML before sending it if you edit the action and change the template to %%[[body]]%%…but WordPress will be getting and storing HTML, not the raw Markdown.

1 Like

Perfect. That works. WordPress converts the HTML automatically.

Hi @agiletortoise,

Thanks for this answer. I have tried it and the automation works, but for some reason wordpress does not recognize the html tags and now I have just a single block of text with all the html tags. As far as I understand it should work, because the block, which wordpress uses is “own html”. Am I the only one experiencing this issue?

Yes, I’ve seen it too. My posts are wrapped in html.

At the Moment I can‘t log in from Drafts to my WordPress Account. Do you know any WordPress Plugins That might Could block the Login?

There are a lot of things that could block login. There’s a few troubleshooting steps above in the post. Most commonly your host simply disallows XML-RPC access by default. What error are you getting in the log (action history button at top of action list) after attempting the action?

Unsure if you take contributing “Integration Guides” but I’d like to submit one for integrating with 1Writer.
This would be an excerpt from an artifact I am currently writing, that is much akin to what Alex Guyot wrote years ago. Kind of an updated version, if you will. Thx

Hello, I am trying to run an action that starts with a prompt to collect a category.

I set up a key called [[dp_cats]] and then include that in the Categories field in the ‘WordPress’ step.

When arriving at my site, all I get is the actual text in the field. Is there no way to have a variable loaded into the categories field (or tag field)??

I’m also experiencing this.

I get a nicely spaced post with HTML tags in it.

I can fix it by selecting the text, cut, then move to the “Text” tab and pasting the HTML in there, but I’d love to skip that step.

Any ideas?

Been trying to use the Wordpress actions:

However when I test them out, the posts do not show up on the Wordpress side. Within Drafts, they seem to say it goes through. This was an error that I saw in the Drafts logs:

Response: undefined Error: undefined Script Error: TypeError: undefined is not an object (evaluating 'response.params[0]') Line number: 26, Column 60

Could all the changes happening on the Wordpress side regarding block publishing be causing issues with these Drafts Actions?

I was frustrated for a minute with the actions not working and saying my WordPress credentials were wrong even though I copied and pasted from 1Password.

It might be obvious to others, but the action failed because of the two-factor authentication on my site.

I can use the XML-RPC option for posting from Drafts by using the setting in Wordfence to skip 2FA for XML-RPC call authentication.

1 Like