Recently, in a WordPress project I have been working on, I had the need to mass set or remove the post password as it was set on various posts that were contained in a WordPress site. The way this site was setup, all the posts were named a certainly prefix as it was essentially being used as a CMS system of sorts to contain and track certain resources. In the beginning design stages of the site, it was determined that a post password would be set on every single post and changed based on the person that needed access to that resource. After working with the site for a few weeks however, it was determined that this wasn’t the case and we could just move forward without passwords on the posts themselves.
After being asked how to quickly remove the passwords, I can up with a quick MySQL update statement that in our case was able to unset the post_password field as it was set on the posts in the wp_posts table for our WordPress site database.
UPDATE site.wp_posts
SET post_password=''
WHERE post_title LIKE 'BR10-%'
AND post_type='post'
As you can see above, I knew the prefix for the posts in which we wanted to reset the passwords for. This made it much easier in this specific case. However, if you have a site where you want to completely remove all post passwords on any post regardless of the title you could do something like the following:
UPDATE site.wp_posts
SET post_password=''
WHERE post_type='post'
This would literally remove anything in the post_password field for everything in the wp_posts table that has the post_type of post. This can really be a useful snippet to know if you need to mass set or remove wordpress post passwords on a site in a hurry without utilizing a plugin of some sorts.
0 Comments