WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need a little MYSQL pointer please (6 posts)

  1. pshero
    Member
    Posted 4 years ago #

    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!

  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    Why not let a plugin do it for you, avoid the need to fiddle with queries..
    http://wordpress.org/extend/plugins/search-and-replace/

  3. pshero
    Member
    Posted 4 years ago #

    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.

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    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>');
  5. pshero
    Member
    Posted 4 years ago #

    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.

  6. Mark / t31os
    Moderator
    Posted 4 years ago #

    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... :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags