I am trying to add the information below into a Wordpress database table (specifically the wp_postmeta table). But I can't figure out how to add the ones with the same node name.
The XML document is:
<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0"
xmlns:excerpt="http://wordpress.org/export/1.1/excerpt/"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:wp="http://wordpress.org/export/1.1/"
>
<channel>
<title>Title</title>
<link>http://localhost/WP/</link>
<description>Just another WordPress site</description>
<pubDate>Mon, 30 Jul 2012 08:53:47 +0000</pubDate>
<language>en</language>
<wp:wxr_version>1.1</wp:wxr_version>
<wp:base_site_url>http://localhost/WP/</wp:base_site_url>
<wp:base_blog_url>http://localhost/WP/</wp:base_blog_url>
<generator>http://wordpress.org/?v=3.3.2</generator>
<item>
<title>IMPORT TEST 1</title>
<link>http://localhost/WP/IMPORT TEST/</link>
<dc:creator>admin</dc:creator>
<wp:comment_status>open</wp:comment_status>
<wp:status>publish</wp:status>
<wp:post_type>post</wp:post_type>
<category domain="category" nicename="plumbing"><![CDATA[Plumbing]]></category>
<category domain="category" nicename="news"><![CDATA[NEWS]]></category>
<wp:postmeta>
<wp:meta_key>thumbnail</wp:meta_key>
<wp:meta_value><![CDATA[decorating8.jpg]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>content</wp:meta_key>
<wp:meta_value><![CDATA[THIS PART IS TO BE FILLED WITH THE TEXT YOU WANT]]></wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>youtube_video_link</wp:meta_key>
<wp:meta_value><![CDATA[]]></wp:meta_value>
</wp:postmeta>
</item>
</channel>
</rss>
The code I have so far is:
<?php
//error display
error_reporting(E_ALL);
ini_set('display_errors', true);
$target_path = "temp/";
$target_path = $target_path . basename($_FILES['feed']['name']);
if(move_uploaded_file($_FILES['feed']['tmp_name'], $target_path)) {
$time = time();
$rand = rand(100,500);
rename("temp/".basename($_FILES['feed']['name']), "temp/".$time.$rand.".xml");
$filename = $time.$rand.".xml";
$objDOM = new DOMDocument();
$objDOM->load("temp/".$filename);
$job = $objDOM->getElementsByTagName("job");
foreach( $job as $value ) {
$title = $value->getElementsByTagName("title");
$link = $value->getElementsByTagName("link");
$post_name = $value->getElementsByTagName("post_name");
$status = $value->getElementsByTagName("status");
$category = $value->getElementsByTagName("category");
$category = $value->getElementsByTagName("category");
$wp:postmeta = $value->getElementsByTagName("wp:postmeta");
$wp:postmeta = $value->getElementsByTagName("wp:postmeta");
$wp:postmeta = $value->getElementsByTagName("wp:postmeta");
$wp:postmeta = $value->getElementsByTagName("wp:postmeta");
$wp:postmeta = $value->getElementsByTagName("wp:postmeta");
}
$f01 = $title->item(0)->nodeValue;
$f02 = $link->item(0)->nodeValue;
$f03 = $post_name->item(0)->nodeValue;
$f04 = $status->item(0)->nodeValue;
$f05 = $category->item(0)->nodeValue;
$f06 = $wp:postmeta->item(0)->nodeValue;
$f07 = $wp:
mysql_connect("localhost", "root", "password") or die(mysql_error());
mysql_select_db("dbname") or die(mysql_error());
//if insert entry
if($title != ""){
$query = mysql_query("INSERT INTO wp_postmeta (meta_key, meta_value )" ) or die(mysql_error());
$current_id = mysql_insert_id();
} else{
//file didn't been upload properly
echo "There was an error uploading the file, please try again!";
}
?>