Today we ran into the need to remove the prefix URL from all database entries that use the Download Manager Plugin. We currently run a staging webserver, and it uses a different URL then the live website URL. Of course this natually causes an handful of issues to deal with. Most of these issues can be handled using a couple of DEFINE varaibles in the wp_config.php file.
The Download Manager plugin stores the URL into the database, and it doesn’t use these defined global variables like it should. This causes a pretty big headache so today we wrote our first blog post about MySQL.
To update fields in a database table, and replace a part of the string, we use the REPLACE function from MySQL. See below our example code which removes the URL domain prefix on the filename column of the table.
UPDATE wp_download_monitor_files SET filename = replace(filename, 'http://staging.anthem.edu/', '/');
You can also use this generic example which helps identify all the peices of the above example:
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, ‘find this string’, ‘replace found string with this string’);
© Copyright 2024 Sethmatics Websites All Rights Reserved.
Recent Comments