Bulk update wordpress posts

Coders. I’m really new in WP Coding, I have zero knowledge, here we are.
I created a plugin (actually found it, but I did some modifications) which update all my wp posts.

Let’s show you the code,

if ( ! class_exists( 'MyPlugin_BulkUpdatePosts' ) ) :

class MyPlugin_BulkUpdatePosts
{
    public function __construct()
    {
        register_activation_hook( __FILE__, array( $this, 'do_post_bulk_update' ) ); //Run this code only on activation
    }

    //Put your code in this function
    public function do_post_bulk_update()
    {
        $posts_to_update = get_posts('numberposts=-1'); //numberposts for post query, "-1" for all posts.
        foreach ( $posts_to_update as $update_this_post ):

        //update query goes here

        endforeach;
    } 
}
endif;

As you can see, it makes a query to the all posts, The main problem is I have 10k+ posts, But when I use this my server gets crushed, I gets a “503 Unavailable”.

How can I make this work by less resources ?

Read more here: Bulk update wordpress posts

Leave a Reply

Your email address will not be published. Required fields are marked *