【发布时间】:2017-04-16 17:17:02
【问题描述】:
我正在使用这个插件,在这里列出:http://mlitzinger.com/articles/instagram-to-wordpress-posts/
我已经安装了 Crontrol 插件,但我只设法让一篇文章导入一次。 Instagram 数据正在正确返回,所以我假设它与帖子插入有关。这是用于插入获取的 Instagram 帖子的数据:
$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;
}
【问题讨论】: