Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter KayBeSee

    (@kaybesee)

    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.

    Plugin Author thaikolja

    (@thaikolja)

    Hi KayBeSee,

    get_imdb_connector_movie() always returns an array as default. See here for an example output: https://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.

    Plugin Author thaikolja

    (@thaikolja)

    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 />";
    	}
    ?>
    Thread Starter KayBeSee

    (@kaybesee)

    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).

    Plugin Author thaikolja

    (@thaikolja)

    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"].

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Array Examples’ is closed to new replies.