Answer the question
In order to leave comments, you need to log in
How to auto post from Instagram to WordPress?
The task is to make automatic posting from instagram in WordPress.
Moreover, the auto-posting scheme is as follows - as a new photo appears on Instagram, the plugin takes the photo and posts it in WordPress, for which it checks the Instagram feed with some frequency.
The plugins I've seen require you to manually place the tag and post yourself. But in order to be fully automatic - has anyone come across such a solution?
Answer the question
In order to leave comments, you need to log in
something like this and run on cron
define('INST_USER_ID','xxxxxxxxxxxx');
define('INST_CLIENT_ID','xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx);
$json = file_get_contents("https://api.instagram.com/v1/users/{INST_USER_ID}/media/recent/?client_id={NST_CLIENT_ID}");
$array = json_decode($json);
header('Content-Type: text/html; charset= utf-8');
$file = $_SERVER['DOCUMENT_ROOT']. 'instagram-log.txt';
$old = file_get_contents($file);
$old_array = explode('\n',$old);
foreach ($array->data as $one){
if ( in_array($one->images->standard_resolution->url, $old_array ) === false ) {
$fp = fopen($file, 'a+');
fwrite($fp, $one->images->standard_resolution->url.'\n');
fclose($fp);
$post_data = array(
'post_title' => $one->caption->text,
'post_content' => '',
'post_status' => 'draft',
'post_author' => 1,
'post_category' => array( 1,2,3,4,5,6 )
);
$post_id = wp_insert_post( $post_data );
$url = $one->images->standard_resolution->url;
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$desc = "";
$file_array = array();
$tmp = download_url( $url );
preg_match('/[^\?]+\.(jpg|jpe|jpeg|gif|png)/i', $url, $matches );
$file_array['name'] = basename( $matches[0] );
$file_array['tmp_name'] = $tmp;
$id = media_handle_sideload( $file_array, $post_id, $desc );
if( is_wp_error( $id ) ) {
@unlink($file_array['tmp_name']);
return $id->get_error_messages();
}
@unlink( $file_array['tmp_name'] );
update_post_meta( $post_id, '_thumbnail_id', $id );
$image_attributes = wp_get_attachment_image_src( $id );
$my_post = array();
$my_post['ID'] = $id;
$my_post['post_content'] ='<img src="' . $image_attributes[0] . '" alt=""/>';
wp_update_post( $my_post );
wp_publish_post( $post_id );
}
}
Try setting up the Recipe in the IFTTT service.
Found this https://ifttt.com/recipes/547-instagram-to-blog , try it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question