如下所示,我创建了一些代码,可以从我的XML文件中获取数据,然后将这些数据添加到我的自定义帖子类型&#39; <&#39;
中的帖子中$wpbb_xml_content = file_get_contents('http://xxxxxx.co.uk/export/peach-upload.xml' );
$xml = simplexml_load_string( $wpbb_xml_content );
foreach ($xml->ExportTable as $ExportTable) {
$title = wp_strip_all_tags( (string) $ExportTable->Job_x0020_Title );
$content = (string) $ExportTable->Job_x0020_Descritpion;
$wpbb_job_post_args = array(
'post_type' => 'jobs',
'post_title' => $title,
'post_content' => $content,
'post_status' => 'publish'
);
$wpbb_job_post_id = wp_insert_post( $wpbb_job_post_args );
}
我对此代码的问题在于,它从XML中获取数据并使用XML Feed的每个表项创建帖子,但它无休止地循环,所以我应该只有〜 26个帖子,但它不断创建26个帖子,所以我想要它做的就是停止一旦它到达XML提要的末尾,我想知道我是否用我当前的代码错误地解决了这个问题。
XML Feed的外观示例:
<Export>
<ExportTable>
<Job_x0020_Title>title 1</Job_x0020_Title>
<Job_x0020_Descritpion>desc1</Job_x0020_Descritpion>
</ExportTable>
<ExportTable>
<Job_x0020_Title>Title 2</Job_x0020_Title>
<Job_x0020_Descritpion>desc2</Job_x0020_Descritpion>
</ExportTable>
</Export>