0

I have encountered this issue many times. I have shifted my wordpress site from one server to another, then I had to run these queries to update the url's in the database :

UPDATE wp_posts SET guid = REPLACE (guid, 'http://localhost/dziners', 'http://www.dzin.test/');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://localhost/dziners', 'http://www.dzin.test/');
UPDATE wp_posts SET post_content = REPLACE (post_content, 'src="http://localhost/dziners', 'src="http://www.dzin.test/');
UPDATE wp_posts SET  guid = REPLACE (guid, 'http://localhost/dziners', 'http://www.dzin.test/') WHERE post_type = 'attachment';

Everything worked fine. Even the custom fields data were showing in the admin section. But when I ran this query :

UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://localhost/dziners','http://www.dzin.test/');

I was unable to see the custom fields data in the admin section.

Just to confirm if the data is getting deleted what I did was, I exported the wp_postmeta table, find and replaced all the http://localhost/dziners urls to http://www.dzin.test/ and imported it back into the database.

But still I was unable to see the data in the admin section. With this, one thing is clear that the data is there in the database but it is not showing in the admin section.

I researched on this a lot to fix this. But I couldn't find any solution to resolve this. And my full site is customised with the custom fields.

Your help will be appriciated. Please help

1
  • This will fail for any serialised data, leading to PHP errors and warnings ( it will fail anyway if you run it on a large enough site, and it doesn't have to be that large ). You should use a dedicated tool for this, such as WP CLI's search replace command
    – Tom J Nowell
    Commented Jan 18, 2017 at 8:01

1 Answer 1

1

Try using Search & Replace plugin - https://wordpress.org/plugins/better-search-replace/

It does everything out of the box.

2
  • Thankyou Ravi for the reply..but is there any other solution without any plugin? I hardly use any plugins.
    – 1991wp
    Commented Jan 18, 2017 at 7:19
  • @1991wp if you remove the comment at the top of the main file, copy the files into your theme, and require the file from functions.php, then you'll have what you want, but without a plugin. Or you could use the plugin directly and save the hassle, there's nothing wrong with plugins it's just something new users get told to stop them installing 10,000 of them then asking why their site's slow and broken
    – Tom J Nowell
    Commented Jan 18, 2017 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.