简短回答:simplexml_load_file()
+ wp_insert_post()
您希望提供XML,并对其进行解析,以获取可用于发表文章的信息。下面是一个简短的示例,因为我不打算为您剖析特定的提要:
$feed = simple_xml_load(\'http://example.com/feed.xml\');
if($feed){
foreach($feed[\'items\'] as $item){
$post_args = array(
\'post_title\' => $item->title,
\'post_content\' => $item->body,
\'post_status\' => \'publish\',
\'post_author\' => 1, // this should represent you, or an author you want these to belong to
\'post_category\' => array(8,39) // optional
);
$post_id = wp_insert_post($post_args);
if($post_id){
// add meta values if you want
$post_meta_values = array(
\'meta_key_slug_1\' => $item->some_information->,
\'meta_key_slug_2\' => $item->some_more_information,
);
// add meta
foreach($post_meta_values as $key => $value) {
update_post_meta($post_id, $key, $value);
}
}
}
}
我将首先引入xml文件,然后执行
print_r()
这样你就可以了解它的结构。