I have the following which works fine but only cache first value for first post and doesn't store data for all movie posts in database. How I can solve this problem? I have also a live perview of this theme.
$cinemamoviename = get_post_meta( $post->ID, "cinama_moviename", true );
$cinemamovieyear = get_post_meta( $post->ID, "cinama_movieyear", true );
$cinemamovienames = urlencode( $cinemamoviename );
$json = file_get_contents( 'http://www.omdbapi.com/?t=' . $cinemamovienames . '&y=' . $cinemamovieyear . '&plot=short&r=json' );
$obj = json_decode( $json );
$movies_title = $obj->Title;
$movies_year = $obj->Year;
$movies_datas = array( $movies_title, $movies_year );
set_transient( 'get_movies_data_intrans', $movies_datas, 365 * DAY_IN_SECONDS );
$movies_details = get_transient( 'get_movies_data_intrans' );
if( false === $movies_details ){ set_transient( 'get_movies_data_intrans', $movies_datas, 365 * DAY_IN_SECONDS ); }
?>
<ul>
<li>
<b>Title</b> :
<?php
if ( $movies_details[0] == null ) {
echo "N/A";
} else {
echo $movies_details[0];
}
?>
</li>
<li>
<b> Relase Date </b> :
<?php
if ( $movies_details[1] == null ) {
echo "N/A";
}else{
echo $movies_details[1];
}
?>
</li>
</ul>