Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function update_my_metadata() {
  2. $args = array(
  3. 'post_type' => 'movies', // Only get the posts
  4. 'post_status' => 'publish', // Only the posts that are published
  5. // 'posts_per_page' => -1 // Get every post
  6. 'post__in' => array(56,57)
  7. );
  8. $posts = get_posts($args);
  9. foreach ($posts as $post ) {
  10. // Run a loop and update every meta data
  11. $key_name = get_post_meta($post->ID, 'field_imdbid', true);
  12. $api = file_get_contents('http://www.omdbapi.com/?i='.$key_name.'&apikey=e2ade02b');
  13. $json = json_decode($api, true);
  14. $getImdbRating = $json['imdbRating'];
  15. $getImdbVotesCount = $json['imdbVotes'];
  16. $getImdbBoxOffice = $json['BoxOffice'];
  17. $getImdbYear = $json['Year'];
  18.  
  19. update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBRATING', $getImdbRating);
  20. update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBVOTESCOUNT', $getImdbVotesCount);
  21. update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBBOXOFFICE', $getImdbBoxOffice);
  22. update_post_meta($post->ID, 'TR_GRABBER_FIELD_IMDBYEAR', $getImdbYear);
  23. }
  24. }
  25. // Hook into init action and run our function
  26. add_action('init','update_my_metadata');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement