Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

How do you ’Find and Replace’ a word in the BP Activity table in the Database? (8 posts)

Started 8 months, 1 week ago by: rossagrant

  • Profile picture of rossagrant rossagrant said 8 months, 1 week ago:

    Basically, I have changed my admin’s display name on my site and this changes the display name EVERYWHERE but in past activity stream posts.

    I can manually change the name in each post in the activity table in the DB but there are 141 instances.

    Is there a way to search and replace the name automatically?

    Thanks

    Ross :)

  • Profile picture of rossagrant rossagrant said 8 months, 1 week ago:

    Any ideas on this people? I see there are strings of SQL to achieve things like this.

  • Profile picture of Travel-Junkie Travel-Junkie said 8 months, 1 week ago:

    That would be something like this:
    UPDATE [tablename] SET [fieldname] = replace([fieldname],'[string_to_find]','[string_to_replace]');

    You’ll need to substitute stuff like [tablename] with the correct values.

  • Profile picture of rossagrant rossagrant said 8 months, 1 week ago:

    @travel-junkie Cheers Boris! Gonna have a play around on a test DB to see if I can get this to work! :)

  • Profile picture of rossagrant rossagrant said 8 months, 1 week ago:

    Hmm… tried this but am told the syntax is wrong

    UPDATE [wp_bp_activity]
    SET [action] = replace([action],’[admin1]‘,’[admin2]‘);

    I’m trying to change all mentions of the admin’s original name, with the new name in the wp_bp_activity table to display the new name in old stream items.

    Anything obviously wrong with that?

    Does filedname refer to the column the string is found in the DB? That’s what I’ve used.

  • Profile picture of Travel-Junkie Travel-Junkie said 8 months, 1 week ago:

    Don’t include the [ ] in the syntax :)

    So it’d be like this:
    UPDATE wp_bp_activity SET action = replace(action,’admin1‘,’admin2‘);

  • Profile picture of rossagrant rossagrant said 8 months, 1 week ago:

    Hahaha, nice one Boris! I’ll test it out! ;)

  • Profile picture of rossagrant rossagrant said 8 months, 1 week ago:

    @travel-junkie Cheers Boris, just got around to testing this, and it works a treat without brackets!

    Changed 145 rows in under a second! Saved me A LOT OF TIME!

    Thanks!