0

I'm managing a couple of hundreds of websites and need to change part of a serialized data. It's a wordpress child theme and inside of the theme's "Options" settings.

Using this script

UPDATE wp_e4e5_options
SET option_value = REPLACE(option_value, 'Copyright | by <a href="https://company.com"', ' ')

a:1:{s:3:"copyright";s:17:"Copyright | by <a href="https://company.com"";}

I was certain, it would just find that part of the serialized data and replace. But it doesn't. It reset the setting to the theme's standard setting. Even when I edit it manually by using Adminer.php in the table, it resets.

I'm aware, that this might be in the wrong forum, since it's Wordpress related, but I believe it's SQL that's the issue here.

So my question is:

  1. If i edit it manually using Adminer.php (simple version of phpMyAdmin), it resets all the settings back to standard. How can I edit only part of the serialized data and only the part shown above?

  2. What makes it "reset" to standard settings?

UPDATE: Thanks to @Kaperto I got this working code now, which gave me a new issue.

UPDATE wp_e4e51a4870_options
SET option_value = REPLACE(option_value, 's:173:"© Copyright - Company name [nolink] | by <a href="https://company-name.com" target="_blank" rel="nofollow">Company Name</a>";', 's:40:"© Copyright - Company name [nolink]";')

The problem is, it's gonna be used as a code snippet with ManageWP looping through several hundreds of websites which all have different company names. So the first part of the string is unique but the rest is the same on all sites, after the pipe |.

So I somehow need to do this:

  1. Find whole series where this string is included | by <a href="https://company-name.com" target="_blank" rel="nofollow">Company Name</a>"
  2. Get the whole series s:173:"© Copyright - Company name [nolink] | by <a href="https://company- name.com" target="_blank" rel="nofollow">Company Name</a>
  3. Replace with new series with updated character count, since company name is different

Is this even achievable with pure SQL commands?

Davallen
  • 61
  • 6
  • when you replace this string, the serialized format is no more valid. to make it valid you have to replace the string size `17`. – Kaperto Dec 05 '19 at 09:10
  • So s:[character count] and has to be updated in correlation to the changed string? – Davallen Dec 05 '19 at 09:24

0 Answers0