I have a simple function that automatically formats the whole post after publishing/updating.
It’s hooked on:
add_action('save_post', 'myFunction');
I would like to format every post, that I already have in database. I know I can open every post and click on update to call the “save_post” hook on myFunction on the post, but my post database is pretty big..
Is it possible to run the function just once on every already published post somehow or update every post so the function will be called by the hook automatically?
Yes, this is possible. Something like this should affect all posts that are currently published. Literally run this once and then disable it by commenting out the add_action or you will have a bunch of unwanted queries to the database.
Running once: With this code placed in your functions.php, the function will run when the front end of your site is loaded in a browser. Load the home page of your site in a browser then disable the function. Confirm that your post format was applied to existing posts.
Edit: If it absolutely must run not more than once, have your function look for an SQL table with a boolean value of true or false. If false or table does not exist, run the function, create the table and set it to true.
Might also consider backing up database and trying an SQL find and replace. Depends on what you are trying to do to all of your posts: