I run a popular forum where one of the members who has made a lot of awesome contributions recently contacted us. He has posted several hundred images from his webshots gallery, but the service is changing as are all the images. I need to change all the image src paths in all of his posts in our mysql database.
He was given the opportunity to download all the images which he has given to me. Because I will be having to do a lot of these changes in production I need to make sure that I don't screw this up.
The image src in his posts look similar to this, where 0103935217 I believe is his user ID.
http://inlinethumb25.webshots.com/47576/2156388770103935217S500x500Q85.jpg
The images downloaded from the service look like this. Notice the S500x500Q85 has been replaced with a random string.
2156388770103935217Reacil_fs.jpg
So I have two tasks:
I need to rename the all the files I've put on my server removing the random characters and the _fs designation.
I need to change the file paths in all of his posts removing domain and container and replacing it with mine. In addition I need to remove the S500x500Q85 designation.
For 1. I have a regex but I'm unsure how to do the replacement 0103935217\w+?_fs
For 2. I know my query needs to be something along the lines of the below. I'm a little unsure how to do this though, is it with a regex?
UPDATE posts SET post_body = replace(post_body, '','') WHERE user_id = 1234
Related
I previously used an old CMS.
I moved to wordpress and I've done a lot of work, but I still have in my very old articles 1000+ internal links pointing to old urls.
I've set up redirects, but I would like to actually replace / delete the very old internal linking in the wordpress database.
I have 3 types of old linking :
/articles.php?lng=fr&pg=425 .......... so like /articles.php?stuff
/news.php?lng=fr&pg=1827 .......... so like /news.php?stuff
/2456-actualite .......... so like /id-actualite
I believe that "Search and replace" and "Better search and replace", both Wordpress plugins are only dealing with exact urls, while the ids are dynamic.
How would you delete those all links in the database, but keeping the hypertext of those links?
Thanks !
Have you tried using WP Cli?
It's a very powerful tool for this kind of problems by running some commands on your server.
Example:
# Search and replace but skip one column
$ wp search-replace 'http://example.dev' 'http://example.com' --skip-columns=guid
Have a look more on their search-replace command.
It is probably impossible to change each URL by hand.. much better way is to use something like this "https://wordpress.org/plugins/search-and-replace/" to replace all URLs you need in the database. - This does not only deal with urls but with any other text too.
I have a rather large spreadsheet that lists out all the images on a client site along with the image URL. It has updated information for the image alt attributes as well as new captions.
Since the list is so large, I'm looking for something like an SQL query or something I could run that would import the necessary information from the spreadsheet and update the related image metadata in the database. I'm not a backend guy, but the guy who usually handles this kind of thing is unavailable for a while, so it's fallen to me. Is this something I can do in MySQL?
edit: I found this post that deals with what seems to be a similar issue. Would I be able to use this method for the image captions?
In case anyone happens to want to solve a similar issue, here's how I solved it.
This post details where alts and captions live in the WordPress database: https://wordpress.stackexchange.com/questions/1777/are-captions-stored-anywhere. I used that as the basis for my process.
First, I ran the following query on the wp_postmeta table and copy/pasted the results into a new sheet in my spreadsheet.
SELECT * FROM 'wp_postmeta' WHERE meta_key LIKE '_wp_atttached_file'
Second, I ran a similar query on the table wp_posts and also put the results in a new sheet.
SELECT * FROM 'wp_posts' WHERE 'post_type' LIKE 'attachment'
I then used a Google Sheets (the spreadsheet software I'm using) add-on to merge each sheet with my main sheet. The posts data I merged on the basis of matching URLs (the data I have to work with in my original spreadsheet). Then I merged the postmeta data based on matching post IDs.
Finally, once I had all of that, I could download my file as a .csv file and import it into the postmeta and posts tables. I made sure to do my first import on a local install of the site so as to not screw with a live site. I'm using Sequel Pro for managing databases, and it has a handy CSV import tool that allows you to do an UPDATE on the postmeta and posts tables. My import used the post IDs and meta_key (for the alts) and post_ID/ID (for the captions) to match up the data.
That's the process that worked for me, though I still did have a dozen images with funky URLs that I just updated manually rather than messing around with Regex.
In my wiki I sent in a request to add a new namespace called 'Exchange', however adding the new namespace will delete all pages with the name 'Exchange:blahblah'. So I would need to change the page name for all these pages before requesting to add the namespace. The problem is that there are just under 1000 pages such as 'Exchange:blahblah' and changing the names of all of them would take up too much time.
My question is how, if possible, can I change the names of all these pages without having to manually alter the name individually. That is, if I wanted to change every exchange page from 'Exchange:blahblah' to 'Exchange1:blahblah', then is there a quick and easy way to change them all. All the pages are under the same category, if that helps.
Any advice would be greatly appreciated.
Add the namespace then run php maintenance/namespaceDupes.php --fix --move-talk from shell. See its documentation for details.
I have a Wordpress Multisite installation, and the root domain is set to root-domain.com. I would like to switch it with one of the sites of the network (site-in-network.com), and make it a root domain.
This way site-in-network.com would become the root domain, and root-domain.com would become one of the sites in the network (100+ sites).
I've done search and replace on a database before, and it worked, but I was dropping a domain all together, so I just replaced domain-a.com with domain-b.com. This time it is different, I want to keep both of them, and just switch the positions in the database.
I guess I would need to run a MySQL query. As far as I know, the root domain was set to something like "www.root-domain.com", and all other sites in the network were like "site-in-network.com" (without the .www part)
The database is about 0.5GB, so it would be good to get it right the first time.
Thank you in advance for any info.
It can be done with a search and replace, but mind you that wordpress is also storing site information in a serialized form in the tables. That means that a default search and replace will break a lot of stuff, so be careful with that.
There is however a script that takes this into account: http://interconnectit.com/products/search-and-replace-for-wordpress-databases/
Download it and put it in your root folder. (And afterwards, delete it!!)
Using this script you could change root-domain.com to root-domain.tmp.com and then site-in-network.com to root-domain.com. After that you could rename root-domain.tmp.com to site-in-network.com. Basicly what Plamen Nikolov suggested to do in the first place.
Here is a little bit of a craftily solution:
You can still workaround the situation with the find and replace technique using fake domain name:
Replace site-in-network.com with some-fake-unique-name.com
Replace root-domain.com with site-in-network.com
Finally some-fake-unique-name.com with root-domain.com.
There is also solution without changing the database, by definining HOME and SITE URL like here: Changing the Site URL
firstly I'll give some background regarding the situation.
I have a website containing approximately 56k pages each page contain a mapped sketch of a machine part. this machine part is made out of smaller parts which are outlined in the image and hold a certain number. when you hover over the numbers a box with the part item code shows up.
I order parts according to this item codes but recently a lot of the items codes have changed, therefore I am looking for a solution.
now I own a database with data on all the 56k parts and I want to link the relevant webpage to each record according to the name of the part(a column in my database), the problem is that the webpages names has no logic name that could connect with the part name in any way but the image that is displayed in the page has the exact name of the part.
I want to rename all the html files I has according to the Images displayed within them. how can I achieve that without renaming all the 56k pages manually?
additionally how can I add the links to all the 56k pages automatically to my database after all the above is done?
Thank you for your patience I know it was long.
If you have a *nix shell, then a simple egrep will get you far
egrep "<img src=\".*\"" -r . > list
The regexp would have to be adapted to match the part you are looking for of course.
You could easily to some search/replace in the resulting list to create a batch script that will do all the renaming for you.
Pick your favorite scripting language and parse each html file to find the image name to use in renaming the file. Personally I would use Perl as it makes parsing the files and updating a database at the same time with the URL easy.