Have you ever tried to publish a post in WordPress with PHP? If no then this post will teach you how to publish a post in WordPress using PHP.

It is a very easy task. What you have to do is just copy the code given in this article and include it in your program and call the function to publish a post in WordPress. Recently I was working to get news feed from various Tech news sites and display them in TechMuzz as show in the picture below.

add wordpress post with php

For this I tried many codes to publish post in WordPress but at the end I had to make it on my own and I did so. After that I thought about sharing it with you guys so you don’t have to waste your time coding it. So here is the code:

You have to set three variable in this code to allow this code to publish on your behalf. First is $client , second one is $username and the last is $password. To set your client you have to replace your domain name in the place of “www.yourdomain.com” .

If you don’t know about xmlrpc.php file then for just knowledge, this is a file that resides in your website by default and is used for Remote Publishing. One more thing to remember is that Remote publishing is enabled by default after WordPress 4.0+. 

// Create the client object

$client = new IXR_Client(https://www.yourdomain.com/xmlrpc.php);

$username = username;  //this user must have writing permissions.

$password = password;

To use this function you need one one that you have to put with the .php file and include in your code:

The code is pretty self-explanatory,  to use this function you have to pass the values for the required variables. That’t it. It will publish a post on your behalf in your WordPress blog/website. You can even post to multiple WordPress blogs/website if you call this function in loop with different User login details.

If you find any problem while using this code or have any query then feel free to ask in the comment section. We will be glad to help you.

Enjoy & Stay Techie…