Я решил это, добавив обработчик AJAX в мои functions.php, извлекая задания через запрос curl, а затем перебирая ленту новостей, вставляя новые сообщения в БД и обновляя уже существующие сообщения.
//CURL request to fetch feed when getting AJAX call
function import_feed() {
$url = "http://url-to-jsonfeed.com";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$data = json_decode($response, true);
create_posts($data);
wp_die();
}
add_action('wp_ajax_import_feed', 'import_feed');
//Loop through JSON data and create post
function create_posts($jsonfeed) {
$data = $jsonfeed['Report'];
if (!empty($data) ) {
foreach ($data as $entry) {
//Set post data before creating post
$post_data = array(
'post_title' => $entry['Entry_Title'],
'post_name' => $entry['EntryID'],
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'entries'
);
if (get_page_by_title($post_data['post_title'], 'entries') == null && empty(get_posts(array('post_type' => 'entries', 'name' => $post_data['post_name'])))) {
wp_insert_post($post_data, $wp_error);
} else if (!empty(get_posts(array('post_type' => 'entries', 'name' => $post_data['post_name'])))) {
$post = get_posts(array('post_type' => 'entries', 'name' => $post_data['post_name']));
$post_id = $post[0]->ID;
$post_data['ID'] = $post_id;
wp_update_post($post_data, $wp_error);
}
}
}
}