Hi cp well really I’m just following the tutorial, it says:
“The script can be placed on any PHP enabled server, so long as it is given a PHP file extension (so the server knows to run it as PHP). The URL must point to your Wordpress installation’s proper path, as explained in the article. The username and password fields must be changed to match your Wordpress username and password. The include path must point to a version of the Wordpress class-IXR.php file, so if not on the same server/account as the Wordpress installation, then you may need to download a copy of that file to include it.”
So I thought it came out of the box as such, but obviously I’ll have to provide those details in a form or something I imagine
Okay, so yes, you will want to create a HTML page that has a form with a field named title, and a field named description. That form should post to your php script. Once you have your form built, post the HTML and your PHP here again and we can help you tie them together.
Okay, to get you started, you need to put the filename of your php script in the action=“” of your HTML form (like so, I also removed the duplicate name attributes you had on several fields)
Then you need to update your PHP script to use the form elements
<?php
include("./wp-includes/class-IXR.php");
$client = new IXR_Client('http://MYSITE.org/xmlrpc.php');
if (!$client->query('wp.getCategories','', 'WHERE-I-PUT-MY-WORDPRESS-USERNAME','WHERE-I-PUT-MY-WORDPRESS-PASSWORD')) {
echo('An error occurred calling wp.getCategories - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$response = $client->getResponse();
$content = array(
'title'=>$_POST['title'],
'description'=>$_POST['article'],
'mt_allow_comments'=>'1',
'mt_allow_pings'=>'1',
'post_type'=>'post',
'mt_keywords'=>$_POST['keywords'],
'categories'=>split(',', $_POST['categories'])
);
var_dump($content); // paste the output of this back to the forum for us to review.
if (!$client->query('metaWeblog.newPost','', 'WHERE-I-PUT-MY-WORDPRESS-USERNAME','WHERE-I-PUT-MY-WORDPRESS-PASSWORD', $content, false)) {
echo('An error occurred calling metaWeblog.newPost - '.$client->getErrorCode().":".$client->getErrorMessage());
}
echo $client->getResponse(); //with Wordpress, will report the ID of the new post
?>
Now I am making a few assumptions, 1) I am assuming the WordPress API will sanitize the data because the examples found on http://life.mysiteonline.org/archives/161-Automatic-Post-Creation-with-Wordpress,-PHP,-and-XML-RPC.html do not tell me that I need to sanitize the data. 2) I am assuming allow_comments and allow_pings are a true/false field and since the form doesn’t specifically ask, I hard coded them to true.
And no error? So it seems you should have a new post in your WordPress installation with a title of new and a article/description of new.
With that said, you can remove the var_dump line, and you can remove your echo $client->getResponse(); (unless you want to know the post ID that was created)
I couldn’t see it published so I just checked the wp admin, and it’s there but as a draft not a published post. I’ll check out the wordpress documentation and see why it isn’t being published. Thanks for all the help cpradio really appreciated
I do want to point out 1 more thing, that you should take very seriously.
Since your PHP script contains your WordPress username and password, anyone that posts information to that script with title, article, keywords, and categories will be able to post an entry to your blog.
One way to protect against this is to have your username and password as fields on your form that must be filled out. If this concerns you, I’ll be glad to help you sort that out, or if you rather take a different approach, I can help provide those as well.
New set of code that accepts username and password from the form
<?php
include("./wp-includes/class-IXR.php");
$client = new IXR_Client('http://MYSITE.org/xmlrpc.php');
if (!$client->query('wp.getCategories','', $_POST['username'],$_POST['password'])) {
echo('An error occurred calling wp.getCategories - '.$client->getErrorCode().":".$client->getErrorMessage());
}
$response = $client->getResponse();
$content = array(
'title'=>$_POST['title'],
'description'=>$_POST['article'],
'mt_allow_comments'=>'1',
'mt_allow_pings'=>'1',
'publish'=>true, // try true instead of '1'
'post_type'=>'post',
'mt_keywords'=>$_POST['keywords'],
'categories'=>split(',', $_POST['categories'])
);
//var_dump($content); // paste the output of this back to the forum for us to review.
if (!$client->query('metaWeblog.newPost','', $_POST['username'],$_POST['password'], $content, false)) {
echo('An error occurred calling metaWeblog.newPost - '.$client->getErrorCode().":".$client->getErrorMessage());
}
echo $client->getResponse(); //with Wordpress, will report the ID of the new post
?>
I also changed the ‘publish’ line to use true instead of ‘1’, maybe that will make a difference.