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."


Post a Comment

Popular posts from this blog

Top Google Adsense Alternatives

Google Adsense is a web tool that allows publishers in the Google Network of content sites to automatically serve text, image, video, and rich media adverts that are targeted to site content and audience. These adverts are administered, sorted, and maintained by Google, and they can generate revenue on either a per-click or per-impression basis.  Google servers advertisers using google adwords platform, while adsense is the publishers platform. Google Adsense is the top Ad Publishers platform over the web ranking number one in web advertising industry. Adsense offers contextual advertisements that covers web sites, blogs, games, videos, mobile browsing etc. What made Google Adsense no. 1 is the reliability, stability, variety of services and large number of publishers including google it self. Also google has a fair platform that detects invalid clicks so google successfully protects its advertisers and also offers its best publishers top CPC. Two reasons are behind people think

CFLDAP Add Active Directory User to a Group

I was trying to add a user to a group and had lots of code formatting etc. I was unable to find a straightforward code to help me. I have prepared the below code to help you using CFLDAP and also I will give you an alternative way using the dsmod command line. Lets start first with the CFLDAP: Now lets add an active directory user to a group using command line: When I wrote the above code I added a bulk list of users to a certain Active Directory group. Sometimes the CFLDAP failed so in the cfcatch I called the dsmode using the cfexecute. Why? Some of the user CN names contained special characters like 'bracket (' this caused an error when using the cfldap to add users to the groups so I had to use the cfexcute which succeeded.