skip to Main Content

I am new to mysql and phpmyadmin so excuse my question if it’s basic.
I need a query to replace the 15$ to 10$ on all posts and pages post_title, post_excerpt and post_content using the insert method not update method.
also is there any way to undo the query if things went wrong ?

4

Answers


  1. Chosen as BEST ANSWER
    UPDATE wp_posts SET post_title = REPLACE WHERE post_type = 'post',post_type = 'page' (post_title, '$15', '10$'), post_content = REPLACE WHERE post_type = 'post',post_type = 'page'(post_content, '$15', '$10'), post_excerpt = REPLACE WHERE post_type = 'post',post_type = 'page'(post_excerpt, '$15', '$10');
    

  2. You should back up your database first from PHPMyAdmin -> Export.

    You can’t REPLACE without UPDATE.

    As a second solution, after backup, if your MySQL dump is small enough, you could edit the SQL file with Notepad++, replace 15$ with 10$ and import everything in a new database and switch DB connections. This would meet the requirement: of using only the INSERT method.

    Login or Signup to reply.
  3. I’m not sure what your database looks like without an example and I’m not sure why you want to avoid the update method but maybe
    this will help you with your question.

    This does use the update function however but I don’t see a way around it other than exporting your database to an sql file, updating the rows through either a script or search and replace in a text editor.

    My solution would be to use your text editor or use a query like

    UPDATE posts SET post_title = REPLACE(post_title,'$15','$10');
    

    You might also want to take a look at this: How to search and replace all instances of a string within a database?

    Login or Signup to reply.
  4. let me introduce my solution :
    replace specific string in posts

    UPDATE wp_posts SET post_title = REPLACE(post_title, ‘$15’, ‘$10’), post_content = REPLACE(post_content, ‘$15’, ‘$10’), post_excerpt = REPLACE(post_excerpt, ‘$15’, ‘$10’) WHERE post_type = ‘post’;

    but I would recommend using the first answer for more covering

    UPDATE wp_posts SET post_title = REPLACE WHERE post_type = 'post',post_type = 'page' (post_title, '$15', '10$'), post_content = REPLACE WHERE post_type = 'post',post_type = 'page'(post_content, '$15', '$10'), post_excerpt = REPLACE WHERE post_type = 'post',post_type = 'page'(post_excerpt, '$15', '$10');
    

    replace specific string in pages

    UPDATE postmeta SET meta_value = REPLACE(meta_value, '$15', '$10');
    

    change on wp yoast SEO plugin values meta_titles and meta_description

    UPDATE wp_yoast_indexable SET title = REPLACE(title, '$15', '$10'), description = REPLACE(description, '$15', '$10');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search