Replacing, Updating, Changing text in WordPress fields is as easy as using the MySQL replace command. Here’s an example for updating the post_title field: update wp_posts set post_title = REPLACE(post_title, ‘Old’, ‘New’) WHERE post_title LIKE ‘%Old%’; This will update all the columns that have the word ‘Old’ in their post_title field with the word ‘New’.… Continue reading In WordPress, Replace Text In All Fields
Tag: MySQL
MySQL remove duplicates
DELETE n1 FROM table n1, table n2 WHERE n1.id > 10000 AND n1.id < 11000 AND n1.id > n2.id AND n1.EMAIL = n2.EMAIL; The above MySQL query will delete duplicate email addresses between the id’s 10000 and 11000. Breaking the query into blocks of 1000 id’s will reduce strain the MySQL server.
MySQL find duplicates
select EMAIL, count(EMAIL) as cnt from TABLE group by EMAIL having cnt > 1 ORDER BY `cnt` DESC The above MySQL query will find and list the number of multiple duplicate emails in a table.
Multiple MySQL query with PHP
// Enter multiple query string $query_str = ” — Update table UPDATE t SET id = id + 1; — Insert into table INSERT INTO example (name, age) VALUES(‘John Doe’, ’23’ ); “; // Explode string into separate queries $query = explode(‘;’,$query_str); // Loop through exploded queries and execute foreach($query as $index => $sql) {… Continue reading Multiple MySQL query with PHP