• I have created a plugin that works a lot like the search and replace plugins – it updates a bunch of posts at once. For a variety of reasons, I want to actually update the post via the wp_update_post function rather than do a direct update to the database. I’m using an ajax user interface to control the update flow – 10 posts are updated per ajax request until all posts are changed. Sometimes thousands.

    The problem I’m running into is that on certain hosts the resource usage it too much to handle and after a certain number of updates something (the web server or the database) falls over. On many hosts, I don’t run into any issues. I’ve attempted to mitigate the problem (looking at the server load when it’s available and pausing until it lowers, pausing after a certain number of updates) but nothing has been fool proof thus far.

    I’d love some opinions on if it would be possible to do these kind of updates in a resource efficient way or if the idea is doomed from the start? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Dion


    Sadly, your idea is doomed from the start. You should not use AJAX (or the REST API) for this purpose, or you will always run into server issues. That is effectively loading a full version of WordPress (and all active plugins) for every 10 posts. In addition, using wp_update_post is extremely inefficient because it will update countless DB entries other than the post content.

    What you’re describing should be handled by a PHP script that directly modifies the post content in the database.

    Thread Starter spartank


    Thank you for the input @diondesigns. The main reason I’ve been trying to use wp_update_post has been to create a revision – and thus make any operation run able to be reverted (until other changes are made). Any idea if its reasonable to create a revision in a way other than wp_update_post?



    What if the user has:

    define('WP_POST_REVISIONS', 1);

    in their wp_config.php file? Your plugin would then replace the user’s revisions with yours, which I suspect might make for an unhappy user…

    (I use the above constant in all my sites and most of my client’s sites. It keeps the database a lot cleaner.)

    • This reply was modified 7 years, 1 month ago by Dion.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom plugin can use too many resources’ is closed to new replies.