Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* FETCH */
- $content = file_get_contents("https://api.instagram.com/v1/users/self/media/recent/?access_token=$accesstoken&count=$count");
- $feed = json_decode($content,true);
- foreach($feed[data] as $image) {
- $id = $image[id];
- $thumb = $image[images][thumbnail][url];
- $fullImage = $image[images][standard_resolution][url];
- $link = $image[link];
- $tags = $image[tags];
- $caption = $image[caption][text];
- $postExists = get_posts(array(
- "meta_key" => "instagram_id",
- "meta_value" => $id,
- "post_status" => true
- ));
- /* If no posts with this instagram_id exists (with any post status), add it: */
- if(empty($postExists)){
- // new post arguments
- $post = array(
- "post_title" => "Instagram " . $id,
- "post_category" => array(get_cat_ID($category)),
- "post_content" => "<p>$caption</p>",
- "post_status" => "publish",
- "post_type" => "post"
- );
- // adding the new post
- $post_id = wp_insert_post($post);
- update_post_meta($post_id,'instagram_id',$id);
- wp_set_post_terms($post_id, $tags);
- // adding the image as attachment
- require_once(ABSPATH . 'wp-admin/includes/file.php');
- require_once(ABSPATH . 'wp-admin/includes/media.php');
- require_once(ABSPATH . 'wp-admin/includes/image.php');
- media_sideload_image($fullImage, $post_id, "Instagram");
- }
- }
Add Comment
Please, Sign In to add comment