Support » Fixing WordPress » Need a little MYSQL pointer please

  • Resolved pshero

    (@pshero)


    I’m revamping a bunch of my old posts that were originally formatted using tables instead of CSS. What I’d like to do is look through the posts and replace any particular string of HTML with the new CSS selectors, for instance, replace

    <tr><td class="step">Step 2</td></tr>

    with

    ‘<h2>Step 2</h2>’

    I’ve tried this:

    UPDATE wp_posts SET post_content = REPLACE(post_content, ‘<tr><td class="step"><div class="step_number">2</div></td></tr>’, ‘<h2>Step 2</h2>’);

    But it throws an error, likely because of the HTML characters or quotes or something. It’s going to be a pain to go through 100 posts and change this stuff unless I can figure out a way to do it globally, so any help would be GREATLY appreciated. I’m sure there’s some little trick, but I’ve spent 2 frustrating hours with Google and am no closer than when I started.

    Thanks in advance!

Viewing 5 replies - 1 through 5 (of 5 total)
  • Why not let a plugin do it for you, avoid the need to fiddle with queries..
    http://wordpress.org/extend/plugins/search-and-replace/

    t3los_,
    Thank you for the reply. I’ve tried the Search And Replace plug-in but it throws errors when HTML is introduced and won’t replace with “” empty rendering it useless for this application.

    Plus, I’d really like to understand how to do it in mysql.

    Your query works if you replace the odd quotes with regular ones..

    UPDATE wp_posts SET post_content = REPLACE(post_content, '<tr><td class="step"><div class="step_number">2</div></td></tr>', '<h2>Step 2</h2>');

    t3los_

    Thanks a million! I knew it must have been something small I was missing, but couldn’t for the life of me figure out what.

    I nearly didn’t point it out, because you mentioned quotes initially i almost assumed you had tried the query with regular quotes…

    Query looked sound though, so i tested it quickly… worked first time with quote corrections..

    Happy to help anyway… 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Need a little MYSQL pointer please’ is closed to new replies.