There are occasions when you’ll come across the need to bulk update your post meta data in WordPress. We recently needed this to update a specific post type to use a new template. Keep in mind this will only benefit you if you need a blanket fix to update all posts with a new meta value.
Don’t let this task scare you off by thinking it requires some complex SQL query. It doesn’t! Rest assured the below snippet can be tailored to solve your bulk update needs.
The function below adds an action to “init” meaning it will load immediately – so don’t forget to remove it when you’re done! Basically this function will loop through all posts of a specific post type, and update the post meta data to match a key with a new value. Be careful and make a DB backup prior to using this code as it will update ALL posts that match the post type specificed in the arguments.