0

I have following code and I want to specify a term description for each actor and director in $tmdb_actors_arr and $tmdb_directors_arr:

// build array
$my_post = array(
    'post_title' => $tmdb_title,
    'post_name' => $wp_movie_slug,
    'post_content' => $tmdb_plot,
    'post_status' => 'publish',
    'post_type' => 'post',
    'tax_input' => array(
        'tmdb2wp_year' => $tmdb_date,
        'tmdb2wp_actor' => $tmdb_actors_arr,
        'tmdb2wp_director' => $tmdb_directors_arr
    ),
);
// insert post built from array above
$post_id = wp_insert_post($my_post);

// instert custom fields
add_post_meta($post_id, 'tmdb_id', $tmdb_id, true);
add_post_meta($post_id, 'imdb_id', $tmdb_imdb, true);
add_post_meta($post_id, 'backdrop', $tmdb_backdrop, true);
add_post_meta($post_id, 'poster', $tmdb_poster, true);
add_post_meta($post_id, 'original_title', $tmdb_orig_title, true);
add_post_meta($post_id, 'tagline', $tmdb_tagline, true);
add_post_meta($post_id, 'trailer', $tmdb_trailer, true);
add_post_meta($post_id, 'og-image', $tmdb_poster, true);
add_post_meta($post_id, 'og-title', $tmdb_title, true);
add_post_meta($post_id, 'og-description', $tmdb_plot, true);

// insert genres as categories
wp_set_post_terms($post_id, $tmdb_genres_arr, 'category');

So how and where do I insert term descriptions for director 'Stephen Spielberg' and actors 'Marlon Brando', 'Morgan Freeman'?

Edit:

// Movie cast
$i = 0;
while ($i < count($tmdb_cast)) {
    $tmdb_actors_arr[] = $tmdb_cast[$i]['name'];
    $i++;
}

// Movie crew
$i = 0;
while ($i < count($tmdb_crew)) {
    if ($tmdb_crew[$i]['job'] === "Director") {
        $tmdb_directors_arr[] = $tmdb_crew[$i]['name'];
    }
    $i++;
}
2
  • Where you define $tmdb_actors_arr and $tmdb_directors_arr and what do this variables contain? – gmazzap Aug 19 '13 at 13:12
  • They contain names of actors and directors for movies, see edit – andyderuyter Aug 19 '13 at 13:49
0

Insert them terms first using wp_insert_term, then associate them to the post.

1
  • Do you have a basic example on how I could do this with the code I have now? – andyderuyter Aug 19 '13 at 17:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.