Many WordPress blog owners these days prefer to post their blog content from outside. This facilitates the site owners to post blog posts without even loging into their WordPress admin panel. WordPress supports XMLRPC which can take requests and perform specific operations i.e. ‘Add Post’, ‘Edit Post’, ‘View Recent Posts’ or ‘Save a draft’.

Lets start coding now, but before we go into any details lets ensure that our WordPress installation is allowing XMLRPC (default is turned off). Go to WordPress Admin => Settings => Writing and ensure the XML-RPC is enabled. Click save after checking the enable box. We are good and our WordPress is ready to take XML-RPC commands.

XML-RPC is by default enabled in WordPress 3.5+ that’s cool. On the other hand what if you are not using XMLRPC you can anytime disable it like this. Just place the following line of code in your themes functions.php file and you are all set.

1

add_filter('xmlrpc_enabled','__return_false');

But for the sake of our article, i assume you will not disable XMLRPC.

We will use IXR Library to incorporates both client and server classes, as it is designed to hide as much of the workings of XML-RPC from the user as possible. A key feature of the library is automatic type conversion from PHP types to XML-RPC types and vice-versa. This should enable developers to write web services with very little knowledge of the underlying XML-RPC standard.

Posting Images and Marking Featured Via WordPress XMLRPC

The new wordpress thumbnail feature is so great, now all you have to do is upload an image and mark it as featured. If this is something you are looking for via WordPress XMLRPC then look at the following code

Based on the code given below you can define your own logic of posting images in your article. Suppose you want to show the uploaded image within your content, you can append the $thumbnail_image within your $body object e.g.

1

$body.="<img src='".$thumbnail_image."'>"

I have made a centralized Word-press control panel where i am posting blog posts in more than 20 different blogs using the same admin area. There is no need to log into 20 blog accounts to post my content. I would love to hear your thoughts on this. Please leave me a comment and let me know. Don’t forget to subscribe our RSS to receive latest updates.our RSS to receive latest updates.

I haven't used and thought of sending post-URL as a parameter. To my knowledge WordPress automatically creates a new post URL (permalink) from the post title. Can you tell me your exact requirement so i can think deeper in this.

WordPress will take categories as an array e.g. $category=”category1, category2″; you can see this at the top of my code. Keep in mind that when you associate a post in multiple categories WordPress will take the category with lowest id while assigning Permalink.

What's the exact problem you are facing?

Bergmp

Nice script friend, thanks, I have a simple question: how do I include images into post, and how to align them?

Code Seo

Sorry for my englis, i'm French but great article to understand the way to multi post.

You have complete control over the loop so just play with it nicely and send as many posts as you want. Loop through the get the entire new posts content in array and loop $client->query('metaWeblog.editPost', $params)) to post multiple posts.

Zeekapitein

Hi

Do you know how to add a custom date to the new post? Thnx for the great post!

WordPress is made to get and update. You can’t just set.
I added the code you need to the samples code … it’s last.

There are two ways to go both explained there. You can’t use a template name but the actual php file name:
basename($template);

To create a page with a different template just assign $page->wp_page_template = $file;
There’s no set_template function but I might add it. I’ll have to think page templates a bit through to make it easier.

Eric

I got the script to work beautifully but I don’t understand how to add an image to my post.

I had a “not 200 http code”. Upon investigating, it’s because the website was using an active “Maintenance Mode” plugin… This is still weird, because when I get to the website using a browser, I do receive a http code 200…

Anyway, we could say it’s solved.

Also, I tested the script with the latest library and it was working perfectly (apart from the acute character breaking, such as é, à… but this is just an encoding problem).

You don’t really add that PHP into your WordPress installation. The XMLRPC protocol is to enable publishing into a remote WordPress website…

Let’s say I want “website1.com” to publish on “blogsite2.com”, I’d put the PHP script on “website1.com” (let’s say because you got a database there that will push post into your “blogsite2.com” wordpress) and configure it using “blogsite2.com” user access, password, and xmlrpc.php path (which would be, by default, “blogsite2.com/xmlrpc.php”).

the category thing is not working, please sort it out,
using array($category) it does not work, but with array(‘Action’,’games’) it works. I want to put a variable in the array. Please tell me how can it be done. The current codes does not work.

It worked for me, i think $category is not meant for passing arrays. You should provide actual categories (which exists in your blog). So this is how you should pass the values $category=”Health, Fitness”; Considering Health and Fitness categories already created in your blog, if not it will simply neglect them.

For passing additional values you should code properly and make sure you provide valid values to $categories and not array.

Contact

thanx for the reply, the category I am assigning are $category=”2010, Action”;

I already have this two categories in my wordpress blog. 2010 and Action exists.
However when I use ‘$categories’=array(‘2010’, ‘Action’) ….It works properly. New posts gets assigned with 2010 & action.
But I want it to be variable. So please tell me I am not able to use this ‘categories’=>array($category),

One more thing the above code works if there is only one value in $category which is assigned before. Just it does not work for multiple categories

Contact

please somebody reply as soon as possible.
I already have this two categories in my wordpress blog. 2010 and Action exists.
However when I use ‘$categories’=array(‘2010’, ‘Action’) ….It works properly. New posts gets assigned with 2010 & action.
But I want it to be variable. So please tell me I am not able to use this ‘categories’=>array($category),

One more thing the above code works if there is only one value in $category which is assigned before. Just it does not work for multiple categories

The utf8_encode is because that particular name came from a database query… so it might not be needed actually…
Also, it IS better to use the IDs of the categories… so you could build yourself a “get_cat_id” function if needed…

Finally, which is probably your issue here, when setting the “category” parameters of the “$post” object, you DO NOT need to redeclare your array as an array.

‘categories’=>array($category) // This is WRONG, since $category is already an array… what this does it place the array into another array, making the category itself to deep to be easily queryable.
‘categories’=>$category // This will work, if $category is already an array.

Contact

thanks for the reply.

Its still not working. I used the codes you mentioned
$category = array(21, // Hardcoded
utf8_encode(‘Catégorie’), // DBB query
‘Action’,
‘2010’
);

and

‘categories’=>$category // This will work, if $category is already an array.

IXR_Library.php.inc should be placed in same folder which contains the rest of the code files. If you plan to place the libraries under specific folder you can do so but you should change the path in this code.

Stian

Hey

I am using this script and it works perfectly. However, it sometimes returns false even tho the post is added to the blog.

Yes you can use metaWeblog.getCategories function to retrieve all the categories before you insert a new post. Use it like this

metaWeblog.getCategories (blogid, username, password)

This will returns an array of structs that contains one struct for each category. Each category struct contains both a description and title field which each contain the name of the category. Following is a format which will be returned by metaWeblog.getCategories

It could be your server settings i.e. “When double_encode is turned off PHP will not
encode existing html entities. The default is to convert everything.”

If that’s not the case, you must be doing something wrong. Posting links was the primary reason why i wrote this code. This is something which is working fine on my end. Please test that $bodycontent is having values as it suppose to be

I am getting a weird error even tough i know var are defined.. used the script as is.. “Notice: Undefined variable: encoding in C:wampwwwremoteWPwp-contentthemesremoteWPsubmitter.php on line 15” – and the same for line 16 – the vars are $title and $keywords..

They are being sent ok to the website i am publishing on but still get this error.. any ideas why ?

gabrielem

Very good script!

Thank you for sharing it, I’m working on something similar, but have difficulties in find how to delete post, can you give me a way to delete a post?

Terry

Hi I use this code it’s work but when I use spin such as { xxxx | aaaa } . it can’t spun. it post all of { xxxx | aaaa } how can I do it

Spin or no spin, whatever content you are posting back to wordpress via XMLRPC you should ensure you do alll the magic before you call
$client->query(‘metaWeblog.newPost’, $params)

Dylan

How would I create a GUI to be able to enter in the necessary information for the post, “title” “body” etc. and have it update and run the php file? Is this possible? It would be nice to be able to fill in the information without having to directly edit the code.

Rubert Fitz

What you are asking is pretty basic stuff. You need to create forms take titles and other data, then validate and then push to wordpress via XML RPC.

So, the code you see above should only be accessed when you have a form post, second everything is validated.

Dylan

I figured it was pretty basic. I’m in a computer science program at school learning C#, php looks very similar, but I don’t know how to do this part of the process:
“then validate and then push to wordpress via XML RPC.”

Ideally, I’d like to make the form to enter in Title, Body, Keywords etc. on a WordPress page. I just don’t know how to pass those values to this php file.

Dylan

Any idea where I could find some sample code to make this happen? I’ve been looking around but I can’t find anything to get me on the right track. I’m reading up some PHP tutorials so hopefully I’ll be able to write some code soon.

Ben

This is a great! But how do you create more than 1 custom field?
$customfields=array(‘key’=>’Author-bio’, ‘value’=>’Autor Bio Here’); // Insert your custom values like this in Key, Value formatThe syntax for a key=>value would be easy, but since it is key=>X, value=>Y if I try to add another key=>email, value=email address it only creates one custom field…Thanks!

Richard

Since it’s an array i think you will be able to add more data to it i.e. $customfields=array('key'=>'Author-bio', 'value'=>'Autor Bio Here', 'key'=>'email', 'value'=>'emailaddress');

Many thanks for this superb post. My only problem is that i don’t manage to have more than just one cutom field + value. How can I set multiple custom fields ?

Thanks

humit

Thanks for great code, it just works. However, I could not figure out how to send values for theme provided fields. I have this theme which adds a youtube video url field into the post page. I tried to send it as a custom field but didn’t work. Do you have any idea for posting theme provided fields?

Thanks.

Jontor

Hi, How to add custom taxonomy in this code? thank you

Eduardo

Hi, i like to to conect to 10 blogs, all of them has a diferent passwords, i make and interface and a database to store all the information, but im storing the passwords in clear text on my database, i like to encript the passwords with md5, but the hash passed dont work to publish, what is the best way to store the passwords in the database and pass to the IXR_library?