Php 从xml数据中获取多个类别,并在wp_insert_post_类别中使用它
我在foreach循环中使用以下while循环从xml文件中获取类别:Php 从xml数据中获取多个类别,并在wp_insert_post_类别中使用它,php,arrays,wordpress,Php,Arrays,Wordpress,我在foreach循环中使用以下while循环从xml文件中获取类别: foreach($mm_rss_xml->channel->item as $mm_item) { $i = 0; while ($xml_getinfo_result->movies->movie->categories->category[$i]) { $tmdb_cats = $xml_getinfo_result->movies->movie->categori
foreach($mm_rss_xml->channel->item as $mm_item) {
$i = 0;
while ($xml_getinfo_result->movies->movie->categories->category[$i]) {
$tmdb_cats = $xml_getinfo_result->movies->movie->categories->category[$i]->attributes()->name; // TMDb Categories
echo "<li>".tmdb_cats."</li>";
$i++;
}
提前感谢您的回答:)我自己想出来了:
$cats = array();
while ($xml_getinfo_result->movies->movie->categories->category[$i]) {
$tmdb_cats = $xml_getinfo_result->movies->movie->categories->category[$i]->attributes()->name; // TMDb Categories
array_push($cats, get_cat_ID($tmdb_cats));
echo "<li>".tmdb_cats."</li>";
$i++;
}
我很困惑,你想添加类别,但它们已经存在了?
$cats = array();
while ($xml_getinfo_result->movies->movie->categories->category[$i]) {
$tmdb_cats = $xml_getinfo_result->movies->movie->categories->category[$i]->attributes()->name; // TMDb Categories
array_push($cats, get_cat_ID($tmdb_cats));
echo "<li>".tmdb_cats."</li>";
$i++;
}
$my_post = array(); // build the needed array for the post itself
$my_post['post_title'] = $tmdb_moviename;
$my_post['post_content'] = $mm_overview;
$my_post['post_category'] = $cats;
$my_post['post_status'] = 'publish';
$my_post['post_author'] = 1;
$my_post['tags_input'] = $tmdb_actors2;
$my_post['filter'] = true;