I’ve tried using do_shortcode() to access the elements from the array as well but it isn’t working:
<?php
$imdbID = get_post_meta($post->ID, "MovieNameIMDBid", true);
$movie = get_imdb_connector_movie($imdbID);
echo "<div class='imdb-info-field'>Genre:</div> " . do_shortcode('[imdb_movie_detail title=' . $movie["title"] . ' detail=genre]') . " <br /><br />";
?>
I would ideally like to access them via a PHP function though because I intend on inserting <br />‘s after each actor, director, writer, etc not just have them as a list of strings.
Hi KayBeSee,
get_imdb_connector_movie() always returns an array as default. See here for an example output: http://pastebin.com/cDaBynJA
To use them in a PHP code is fairly simple. If you want to use arrays in echo, use implode() function. Example:
<?php
$imdb_id = "tt0478970"; //get_post_meta($post->ID, "MovieNameIMDBid", true);
$movie = get_imdb_connector_movie($imdb_id);
echo "Title: " . $movie["title"] . "<br />";
echo "Genres: " . implode(", ", $movie["genres"]) . "<br />";
?>
Hope I could help you.
If you want to insert a <br /> after each actor, use foreach() loop:
<?php
$imdb_id = "tt0478970"; //get_post_meta($post->ID, "MovieNameIMDBid", true);
$movie = get_imdb_connector_movie($imdb_id);
foreach($movie["actors"] as $actor) {
echo $actor . "<br />";
}
?>
Awesome! Thank you so much.
One last question, if I wanted to access an individual element in the array? I’m thinking in particular runtime I want to just access the 2nd element (total minutes).
If they’re named as they are in the runtime array, you can access them by using $movie["runtime"], or, if you want to go deeper, $movie["runtime"]["minutes"].