将 Instagram 照片导入为 WordPress 帖子

Import Instagram photos as WordPress posts

我正在使用这个插件,布局如下:http://mlitzinger.com/articles/instagram-to-wordpress-posts/

我已经安装了 Crontrol 插件,但我只设法得到一个 post 来导入一次。 Instagram 数据已正确返回,因此我假设它与 post 插入有关。这是用于插入获取的 Instagram posts:

的数据
$json_feed = file_get_contents($url, false, $args);
$json_feed = json_decode($json_feed);

foreach($json_feed->data as $post):
    if(!slug_exists($post->id)):
        $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_date'     => date("Y-m-d H:i:s", $post->created_time),
            'post_date_gmt' => date("Y-m-d H:i:s", $post->created_time),
            'post_status'   => 'publish',
            'post_title'    => $post->id,
            'post_name'     => $post->id,
            'post_category' => array(7)
        ), true);
    endif;
endforeach;

function slug_exists($post_name){
    global $wpdb;
    if($wpdb->get_row("SELECT post_name FROM wp_posts WHERE post_name = '" . $post_name . "'", 'ARRAY_A')):
        return true;
    else:
        return false;
    endif;
}

我决定使用 https://ifttt.com/,而不是尝试创建我自己的每次 Instagram 更新时都必须维护的插件,因为它包括 Wordpress 和 Instagram。它侦听 Instagram post,然后使用我定义的格式在 Wordpress 中插入 post。