updating serials

One question I’m often asked by clients who want to work on the look and feel of their WordPress powered website by creating a development environment is “can’t I just copy and paste”?

Can you?

Yes and no. Much of your WordPress site is dependent on where you fill out the WordPress Address and Site Address (under Settings > General). This is where you can also give WordPress it’s own directory. If you change that address, it does cascade through some parts of WordPress.

However that doesn’t change everything.

When you add an image or link to an internal page within WordPress, they are added as full URLs, not relative URLs. Why does that matter? A relative URL looks like this: /path/my-file.html, whereas a full URL instead looks like http://www.example.com/path/my-file.html. There are reasons for this choice which you (and I) may or may not agree with. If you want to delve into that, please read this 7 year old ticket and commentary.

However, it is straightforward to fix these URLs with a SQL update/replace query. There are also many plugins which help manage this for you if the thought of SQL makes you queazy. Always make backups first!

Ok, does that address everything?

No. Many themes and plugins need to store lots of data in an efficient manner. They do this by using an array, but not just any array, they use serialized arrays.

A serialized array is similar to a normal array in that it stores multiple pieces of information in one place. What makes these special? It lets you store an array in the database, which otherwise is set to only store plain numbers, text, and dates.

There’s a lot to unpack in this, the simple versions is that it creates a compressed version of the array and records how long it should be so it can be decoded properly.

In php the code would look like this:

$settings = array(
'color' => 'green',
'path' => 'https://domain.com'

when that is serialized, it will look like this:


Why is that a problem?

While you can change that url, “https://domain.com” to “https://example.com” with basic search and replace, the serialized part that s:18 wouldn’t change automatically to s:19. That mismatch would break the PHP code.

Thankfully there are multiple plugins and tools to help you update serialized options. As always, make a backup first!

If you have questions for your specific environment, please contact me.

Learn more: