Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function update_my_metadata() {
- $args = array(
- 'post_type' => 'movies', // Only get the posts
- 'post_status' => 'publish', // Only the posts that are published
- // 'posts_per_page' => -1 // Get every post
- 'post__in' => array(56,57)
- );
- $posts = get_posts($args);
- foreach ($posts as $post ) {
- // Run a loop and update every meta data
- $key_name = get_post_meta($post->ID, 'field_imdbid', true);
- $api = file_get_contents('http://www.omdbapi.com/?i='.$key_name.'&apikey=e2ade02b');
- $json = json_decode($api, true);
- $getImdbRating = $json['imdbRating'];
- $getImdbVotesCount = $json['imdbVotes'];
- $getImdbBoxOffice = $json['BoxOffice'];
- $getImdbYear = $json['Year'];
- update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBRATING', $getImdbRating);
- update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBVOTESCOUNT', $getImdbVotesCount);
- update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBBOXOFFICE', $getImdbBoxOffice);
- update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBYEAR', $getImdbYear);
- }
- }
- // Hook into init action and run our function
- add_action('init','update_my_metadata');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement