[英]Adding photos from instagram to media library wordpress
I have created the following php file to get the instagram photos for a specific user. 我创建了以下php文件来获取特定用户的instagram照片。 Can anyone point me in the right direction as to how I can then add these photos to the media library in my wordpress site?
有人可以向我指出正确的方向,然后再将这些照片添加到我的wordpress网站中的媒体库中吗?
<?php
/**
* Template Name: Cronjob
*/
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://api.instagram.com/v1/users/******/media/recent/?access_token=*************&count=5");
$result = json_decode($result);
foreach ($result->data as $post) {
$new_post = wp_insert_post( array(
'post_content' => '<a href="'. esc_url( $post->link ) .'" target="_blank"><img src="'. esc_url( $post->images->standard_resolution->url ) .'" alt="'. $post->caption->text .'" /></a>',
'post_name' => $post->id,
'post_type' => 'instagram'
), true );
}
?>
Have you tried using Instagram Importer-Plugin ? 您是否尝试过使用Instagram Importer-Plugin ?
Should do the job for you! 应该为你做这份工作! :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.