admin管理员组

文章数量:1405916

There are 2 tasks, there is a site X on which there are 1,500 posts, each entry has a title, a thumbnail and 3 metadata. You need to export these entries to other sites. Those. first you need to write a microapi that will generate json for example, and on the side of other sites (where you need to parse these same entries) a plugin that will receive the same json in the url and create entries. The option of exporting xml and importing to other sites is not suitable, you just need to make a script. I made json generation, it remains to do import of records on the basis of json. The main question is how to make imports. so that it works stably, because running foreach from 1500 wp_insert_post is not a good option, right? Please tell me in which direction to look at the implementation of such a task.

Thanks!

There are 2 tasks, there is a site X on which there are 1,500 posts, each entry has a title, a thumbnail and 3 metadata. You need to export these entries to other sites. Those. first you need to write a microapi that will generate json for example, and on the side of other sites (where you need to parse these same entries) a plugin that will receive the same json in the url and create entries. The option of exporting xml and importing to other sites is not suitable, you just need to make a script. I made json generation, it remains to do import of records on the basis of json. The main question is how to make imports. so that it works stably, because running foreach from 1500 wp_insert_post is not a good option, right? Please tell me in which direction to look at the implementation of such a task.

Thanks!

Share Improve this question edited Dec 3, 2019 at 12:40 fuxia 107k39 gold badges255 silver badges459 bronze badges asked Dec 3, 2019 at 7:31 user2792900user2792900 32 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

You could always give it a try, i've imported around 300 posts at the same time before so, it shouldn't be that big of a deal. You could try the following methods if you have problems with importing them all at once.

  • Try re-defining WP_MEMORY_LIMIT and increase it to i.e. 1024MB
  • Try increasing the max_execution_time (Check this link for more information)
  • Try to split/chunk the array in a few different arrays and add a usleep after every iteration

Please note that within the foreach $id = wp_insert_post() will set $id to the ID of the Post/Page that is being added. If desired you can use this variable to add i.e. meta_values, thumbnails, etc.

Good luck!

本文标签: How to import posts correctly