0
votes

I have moved a newly built WordPress site from a sub directory in the remote server, to the root directory. I have a couple of custom post types with meta data associated with them, including images metadata (i.e. file & URL). Obviously I had to remove the sub directory from the URL. I did so with a replace SQL query.

Now wordpress doesn't recognize the meta data. When I write the following code:

 $img = get_post_meta($post->ID,"mf_logo",true);
 var_dump($img);

I get "bool(false)". I have tried to upload a new image, and it is showing. I then manually changed its URL through MySQL and again it wasn't recognized.

It is important to note that the problem only happens with meta data in the form of array, and not with 'normal' meta-data

Your kind help would be most appreciated.

1
Hi Matanya, where you able to solve this?... if so how did you do it?MariaZ

1 Answers

1
votes

When using meta data (update_post_meta, get_post_meta...) arrays will be automatically serialized in db :

http://codex.wordpress.org/Function_Reference/update_post_meta

A passed array will be serialized into a string.

And you cannot simply replace strings in a serialized array :

$data = array('key'=>'value');
echo serialize($data);

This will output : a:1:{s:3:"key";s:5:"value";}

If you simply replace key or value with a shorter/longer string, il will break the data :

  • a:1:{s:3:"key";s:5:"replace";} is incorrect
  • a:1:{s:3:"key";s:7:"replace";} is correct

You can make a batch to handle this.

But prior to this, do you know you can let wordpress in its own directory and make it accessible from root directory, without breaking links ?

Take a look here : http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install