I'm while using following while loop in a foreach-loop to obtain groups from an xml file:

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++;
}

provides me with:

  • action
  • drama
  • thriller

Now, how do i add these groups into wordpress groups? (they're already put in wordpress, so that they don't have to be added in any longer)

I personally use the next for adding the publish into Wordpress:

$my_post = array();
    $my_post['post_title'] = $tmdb_moviename;
    $my_post['post_content'] = $mm_overview;
    $my_post['post_category'] = // I am stuck here...
    $my_post['post_status'] = 'publish';
    $my_post['post_author'] = 1;
    $my_post['tags_input'] = $tmdb_actors2;
    $my_post['filter'] = true;

$posted_id = wp_insert_post($my_post);

add_post_meta($posted_id, 'test', $average_rating);

} // end foreach loop

Thanks ahead of time for just about any solutions :)

I believed it myself:

$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++;   
}

Then place the array here:

$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;