I ought to begin by saying I've no php experience what so ever, however i know this script can not be that ambitious.

I am using Wordpress' metaWeblog API to batch the development of hundreds of posts. Each publish requires a discrete title, an account, and url's for 2 images, the second being custom fields.

I've been effective creating one publish by by hand entering data in to the following file

<?php    // metaWeblog.Post.php
$BLOGURL = "http://path/to/your/wordpress";
$USERNAME = "username";
$PASSWORD = "password";

function get_response($URL, $context) {
if(!function_exists('curl_init')) {
die ("Curl PHP package not installed\n");

/*Initializing CURL*/
$curlHandle = curl_init();

/*The URL to be downloaded is set*/
curl_setopt($curlHandle, CURLOPT_URL, $URL);
curl_setopt($curlHandle, CURLOPT_HEADER, false);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($curlHandle, CURLOPT_POSTFIELDS, $context);

/*Now execute the CURL, download the URL specified*/
$response = curl_exec($curlHandle);
return $response;

function createPost(){
/*The contents of your post*/
$description = "post description";

/*Forming the content of blog post*/
$content['title'] = $postTitle;
$content['description'] = $description;
/*Pass custom fields*/
   $content['custom_fields'] = array(
array( 'key' => 'port_thumb_image_url', 'value' => "$imagePath" ),
array( 'key' => 'port_large_image_url', 'value' => "$imagePath" )
/*Whether the post has to be published*/
$toPublish = false;//false means post will be draft
$request = xmlrpc_encode_request("metaWeblog.newPost",
array(1,$USERNAME, $PASSWORD, $content, $toPublish));

/*Making the request to wordpress XMLRPC of your blog*/
$xmlresponse = get_response($BLOGURL."/xmlrpc.php", $request);
$postID = xmlrpc_decode($xmlresponse);
echo $postID;

So that they can bare this short, this is actually the most fundamental illustration of the script that iterates via a directory and it is "supposed" to pass through the variables $postTitle, and $imagePath and make the posts.

<?php     // fileLoop.php

$folder = 'foldername';
$urlBase = "images/portfolio/$folder";//truncate path to images

if ($handle = opendir("path/to/local/images/portfolio/$folder/")) {

/*Loop through files in truncated directory*/
while (false !== ($file = readdir($handle))) {
    $info = pathinfo($file);
    $file_name =  basename($file,'.'.$info['extension']);   // strip file extension

    $postTitle = preg_replace("/\.0|\./", " ", $file_name); // Make file name suitable for post title !LEAVE!
        echo "<tr><td>$postTitle</td>";

    $imagePath = "$urlBase/$file";
        echo " <td>$urlBase/$file</td>";

    createPost($postTitle, $imagePath);




It's designed to work such as this,

  1. fileLoop.php opens your directory and iterates through each file
  2. for every file within the directory, a appropriate publish title(postTitle) is produced along with a url path(imagePath) towards the server's file is created
  3. each postTitle and imagePath is passed towards the function createPost in metaWeblog.php
  4. metaWeblog.php produces the publish and passes back the publish id to complete creating the table row for every file within the directory.

I have attempted proclaiming the function in fileLoop.php, I have attempted mixing the files completely. It either produces the table with all of files, or does not step with the directory this way. I am missing something, Yes, it. I'm not sure how you can incorporate $Publish_ here, or use periods when i stated I am very a new comer to programming in php.