Import 100k posts to WordPress
-
Hello,
I have some problem with importing about 200k posts from a different source to wordpress. I createt a custom Plugin that should do this. I upload a JSON File with all the needed data in it. The Json looks like this: https://pastebin.com/JUzUexbL
In the JSON File that should be proceeded are about 150 entrys of persons, some persons own up to 500 candles and 200 condolences. So about 100k posts, because every person, every candle and every condolence is a single post.
I am doing this with this js-script that posts via admin-post to a proceed-script.
The problem is, that i get about 90% a timeout back from ajax. So how could i imporove my solution approach?
var $ = jQuery; $(document).ready(function() { $.getJSON(WP.jsonfile, function(data) { var failed = []; var flag = true; var count = -1; var total = data.length; var step = 100 / total; $(".my_progregg_bar .progress_percentage").text("0 / " + total); $.each(data, function(index, value) { if (flag) { $.ajax({ url: WP.ajax_url, method: "POST", async: true, data: { action: "epimport", data: value }, success: function(e) { count++; console.log(e); $(".my_progregg_bar .inner").css({"width" : step*count + "%"}); $(".my_progregg_bar .progress_percentage").text(count+1 + " / " + total); }, error: function(e) { failed.push(index); console.log(e); } }); } else { count++; } }); }); });
PHP-Script:
<?php $sterbefall = EP_STERBEFALL::setup($_POST["data"]); $sterbefall_post = wp_insert_post(array( "post_title" => $sterbefall->name, "post_status" => "publish", "post_type" => "sterbefall", )); $attachment = array( "post_mime_type" => "image/jpeg", "post_parent" => $sterbefall_post->ID, "post_title" => "Parte " . $sterbefall->name, "post_content" => "", "post_status" => "publish" ); $attachment_id = wp_insert_attachment($attachment, $sterbefall->parte, $sterbefall_post); if (!is_wp_error($attachment_id)) { require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attachment_data = wp_generate_attachment_metadata( $attachment_id, $upload_file['file'] ); wp_update_attachment_metadata( $attachment_id, $attachment_data ); } $attachment = array( "post_mime_type" => "image/jpeg", "post_parent" => $sterbefall_post->ID, "post_title" => "Portrait " . $sterbefall->name, "post_content" => "", "post_status" => "publish" ); $portrait_id = wp_insert_attachment($attachment, $sterbefall->portrait, $sterbefall_post); if (!is_wp_error($portrait_id)) { require_once(ABSPATH . "wp-admin" . '/includes/image.php'); $attachment_data = wp_generate_attachment_metadata( $portrait_id, $upload_file['file'] ); wp_update_attachment_metadata( $portrait_id, $attachment_data ); } update_field("death_die_date", $sterbefall->sterbedatum, $sterbefall_post); update_field("death_funeral_place", $sterbefall->ort, $sterbefall_post); update_field("death_parten", array($attachment_id), $sterbefall_post); update_field("death_portrait", $portrait_id, $sterbefall_post); foreach ($sterbefall->gedenkkerzen as $kerze) { wp_insert_post(array( "post_title" => $kerze->text, "post_status" => "publish", "post_type" => "gedenkkerze", "post_date" => $kerze->timestamp, "post_parent" => $sterbefall_post )); } foreach ($sterbefall->kondolenzen as $kondolenz) { $kondolenz_id = wp_insert_post(array( "post_title" => $kondolenz->name, "post_status" => "publish", "post_type" => "kondolenz", "post_date" => $kondolenz->timestamp, "post_parent" => $sterbefall_post )); update_field("condolence_text", $kondolenz->text, $kondolenz_id); } ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Import 100k posts to WordPress’ is closed to new replies.