I am trying to automatically "add-new" Wordpress post when a Youtube User uploads a new video. Using wp_insert_post(); I can echo what I need to, but how do I write a function that determines: "If youtuber posts new video, then echo results, if else do not post"?

I have been using gdata.youtube.com to decode the json format with my queries, pulling and echoing the data into my theme.

Unfortunately I do not know how to proceed in grabbing the "latest video".

We will use "markiplierGame" as an example Youtuber to pull from.

Example URL: http://gdata.youtube.com/feeds/api/users/markiplierGame/uploads?max-results=50

// User inputs his Youtube ID in theme-options.
$youtuber = get_post_meta ($post->ID, 'youtuber_id', $single = true);

// The ID is then injected into the gdata variable.
$youtuber_gdata= file_get_contents("http://gdata.youtube.com/feeds/api/users/{$youtuber }/uploads?max-results=50");

// json data is then decoded.
$uploads = json_decode($youtuber_gdata);

// Grab the terms needed from decoded gdata
// "entry", "yt$statistics", and "viewCount" are examples of data I can pull.
$new_videos = $uploads->{'entry'}->{'yt$statistics'}->{'viewCount'};

Can anyone help me figure out how to grab the latest video from the json url? I need this to be accurate, or even be able to pull all previous uploads from a bigger youtube user.

Thanks for the assistance!

  • Are you looking for wp_insert_post()? – Pat J Jun 19 '14 at 3:11
  • Yupp, sounds like thats it! This is my first theme, so Im a bit new to the in-depth wordpress functions. How can I pull the latest video of a youtube user without using the youtube API v3? – FlannelBeard Jun 19 '14 at 3:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.