Skip to main content

Publish to Wordpress using JSON API plugin and Coldfusion

I was using Postie to automatically publish to wordpress blog. I was searching a better method of publishing using soap api or json api. I found an excellent json plugin that can be used to publish posts and comments to wordpress.
Please follow the below step by step, this code will let you publish automatically for froma different interface to wordpress rather than using postie or email.

Step one: Install json plugin, enable the plugin and then go to settings > JSON API and  activate post

Step two: you have to modify the file: yourwordpressdirectory/wp-content/plugins/json-api/controllers/post.php

Please replace the file content with the below or add the missing Authenticate method. This method is necessary to authenticate a user to wordpress to be able to post content without a valid session.

Controller name: Posts
Controller description: Data manipulation methods for posts
class JSON_API_Posts_Controller {
  public function create_post() {
    global $json_api;
    if (!$json_api->query->nonce) {
      $json_api->error("You must include a 'nonce' value to create posts. Use the `get_nonce` Core API method.");
    $nonce_id = $json_api->get_nonce_id('posts', 'create_post');
    if (!wp_verify_nonce($json_api->query->nonce, $nonce_id)) {
      $json_api->error("Your 'nonce' value was incorrect. Use the 'get_nonce' API method.");
    $post = new JSON_API_Post();
    $id = $post->create($_REQUEST);
    if (empty($id)) {
      $json_api->error("Could not create post.");
    return array(
      'post' => $post
* Attempts to authenticate user if author and user_password fields exist
* @return void
* @author Achillefs Charmpilas
  private function authenticate() {
    global $json_api;
    if ($json_api->query->author && $json_api->query->user_password) {
      $user = wp_signon(array('user_login' => $json_api->query->author, 'user_password' => $json_api->query->user_password));
      if (get_class($user) == 'WP_Error') {
      } else {
        if (!user_can($user->ID,'edit_posts')) {
          $json_api->error("You need to login with a user capable of creating posts.");
    } else {
      if (!current_user_can('edit_posts')) {
        $json_api->error("You need to login with a user capable of creating posts.");
Step three: Create a component (Class) publish.cfc first you need to request nonce code this is returned using the first cfhttp call and then I pass it to the create_post method of the json-api. The code below is very clear and self explanatory

<cfcomponent output="false">
 <cfhttp url="http://yourwordpressurl/?json=get_nonce&controller=posts&method=create_post" result="nonce" />
  <cffunction name="createPost" access="public" output="true" returntype="any" hint="Post">
      <cfargument name="status" required="true" type="string">
      <cfargument name="title" required="true" type="string">
      <cfargument name="content" required="true" type="string">
      <cfargument name="author" required="true" type="string">
      <cfargument name="user_password" required="true" type="string">
      <cfargument name="categories" required="true" type="string">
      <cfargument name="tags" required="true" type="string">
      <cfhttp url="http:// yourwordpressurl/api/posts/create_post/" result="addpost">
      <cfhttpparam name="nonce" type="URL" encoded="yes" value="#DeserializeJSON(nonce.filecontent).nonce#">
      <cfhttpparam name="status" type="URL" encoded="yes" value="#status#">
      <cfhttpparam name="title" type="URL" encoded="yes" value="#title#">
      <cfhttpparam name="content" type="URL" encoded="yes" value="#content#">
      <cfhttpparam name="author" type="URL" encoded="yes" value="#author#">
      <cfhttpparam name="user_password" type="URL" encoded="yes" value="#user_password#">
      <cfhttpparam name="categories" type="URL" encoded="yes" value="#categories#">
      <cfhttpparam name="tags" type="URL" encoded="yes" value="#tags#">
      <cfreturn addpost />

Step Four: Now in your cfm page something like post.cfm you invoke the class as below:

<cfset postCFC = createObject("component", "publish")>

Now call the method and pass the content you want to publish:

<cfset postCFC.createPost("Publish","#title#","#content1#","username","password","#category#","#tags#")>

The create_post method attributes above are as below:

1- Post status (Draft, Published)
2- Post Title
3- Post Content
4,5- Username and password for a user who has authority to publish
6- list of categories
7- list of tags

Enjoy auto posting and or a new posting interface to wordpress. If you have any question please comment to the post.

Copying the content and posting it in another blog is strictly prohibited.


  1. Hi there. I am using your article successfully to post to my blog but it seems to stop working after the content variable gets over about 6000 characters. I am not sure if it's a limit with the CFC or with Wordpress.

    Can you help on this?

    1. This issue definitely is not caused by coldfusion, you have to check the json plugin. Send them an email and let me know the respond.

    2. I agree from what I have tested. It is a limit on the json plugin. I'll put in a support request today and get back to you on it. Thanks

    3. I will be honest – I ditched ClickBank and AdSense altogether from my blog….reason being there are too many merchants who’s products and services either get banned or leave ClickBank and as for AdSense, it gives visitors to your website another route to click and leave your site. If you have affiliate programs and products already on your site, you are guaranteed to make more money with them than through AdSense, unless your are driving some serious traffic. As for InfoLinks, it just looks spammy and the keywords and ads that appear are not targeted most the time. I personally say just do away with ads and ad networks and focus on affiliate programs to monetize your blog that have one or few solid products to offer, because like I mentioned, you will make more money that

  2. Hello! I found this page very informative, but can't seem to get it to work ... I'm wondering if there's something in the later versions of WP that prevents it from posting ...

    when I manually go to the first url (http://?????.com/blog/?json=get_nonce&controller=posts&method=create_post) I get the response:

    and the second url in the cfc (http://?????.com/blog/api/create_post/) brings me to the main blog page ...

    I'm not sure if you're still supporting this code, but, if you are, would appreciate some advice! Thanks!

  3. hello,
    i want to know that this plugin is require for third party api integration?

    1. In this specific case, I had to use this plugin.

  4. I am getting the below error even i am trying it by admin
    "error":"You need to login with a user capable of creating posts."}

    1. The JSON API plugin hasn’t been tested with the latest 3 major releases of WordPress. It may no longer be maintained or supported and may have compatibility issues when used with more recent versions of WordPress.

    2. might be.
      i am using latest 4.9.4
      on which version it is working perfect.

    3. The plugin was tested up to:4.3.15

  5. "you are right after several time of adsense application rejection many people think that “Ohhh, now i can’t be able to do this” and many of them give up from blogging but it shouldn’t be.

    Google checks the passion and consistency of Bloggers so, we no need to worry about my adsense application is not being accepted. I think 3 or 4 time rejection is normal thing in these days.

    Thanks Bro for sharing your experience with us. Newbies will learn lot’s of things from here."


  6. I think this is among the most important info for me. And i am glad
    reading your article. But want to remark on some general
    things, The site style is great, the articles is really
    nice. buy fake id online


Post a Comment

Popular posts from this blog

Error: Write to Disk Access Denied - Troubleshooting - BitTorrent

I have downloaded Bit Torrent software and when trying to download I got an error after few seconds saying: Error: Write to Disk Access Denied Solving this problem is so simple: Shut down BitTorrent program. Go to Start and in the small search box on top of windows start button start typing Bittorrent and the program will show, right click with the mouse on the icon and Run as Administrator. All ur problems are sorted out now and you can enjoy downloading... Good Luck.

Coldfusion Facebook Graph API publish to your wall and your friends walls

In this tutorial we will learn by full coldfusion Graph API code example how to publish on your wall and your friends walls. This application uses new oauth authentication method. The code is divided into four files: we will first start with a file called index.cfm: <cfoutput>         <!--- Your FB application IDS --->       <cfset api_key = ""/>     <cfset secret_key = ""/>     <cfset appID = ""/>     <!--- create a connection to the fb graph cfc --->     <cfset graphCFC = createObject("component", "graph").init(#appID#, #api_key#, #secret_key#) />     <!--- If user is authenticated or his access token is set create a cookie --->        <cfif not isdefined("cookie.access_token") and isdefined("url.access_token")>         <cfset cookie.access_token=url.access_token>     </cfif>     <!--- If the user is authenticated and access token

IDLE subprocess didn't make connection Python 3.7

After installing Python on Windows 10. When trying to open IDLE, Python's IDE, you might get a  message saying that " IDLE's subprocess didn't make connection . Either IDLE can't start a subprocess or personal firewall software is blocking the connection ". To solve this issue just run IDLE as an Administrator, by right click on the IDLE icon and click Run as administrator. See Photo below: