Featured images when migrating from mutli-site to single site install.

Here's an interesting one....

I'm in the process of migrating some client sites from multi-site into single site Cpanel accounts. The network uses domain mapping via addon domains.

I've found that the "simple" way to do this is to download the "files" folder from the blog.dir, along with exporting various settings from plugins etc and the wordpress export file.

I can then create the cpanel account, unmap the domain, remove the addon etc.

Then after installing wordpress, set everything up and upload the "files" folder containing all the images etc.

At this point I have tried various methods to get images into the media library as follows:

1. Use phpMyAdmin to change the url of the folder to match the new location of the files folder. (works but need to change the location of the "files" folder and change the name to "uploads")

2. Use "add from server" plugin to add files to the correct folder having set up first. (This adds all the files to the media library, including all the various image sizes used by featured images in the theme etc).

3. Change the path of the media library to the new location and name in wp-config. (works and you can upload the folder to any location).

Sorry for the long description but I wanted you to be aware of the process.

This technique seems to work for all aspects of the migration and addresses the problem of images not displaying and of using the media library.

The problem I have is that I no longer have any featured images being displayed or the information retained in the post. In other words, if I go into the post editor, the featured image field is blank.

I am using Genesis themes.

My question is, where is featured image information stored and how can I restore it after migration?

Has anyone done this successfully?

Thanks
Ian

  • aristath

    Hello again @octavian,

    The featured images are stored as post meta.
    However, these are stored as IDs if I remember correctly and not as a URL.
    If you use the 1st method (simply changing the URLs of images in the DB) then you should have featured images.
    Other methods will fail because the ID of the image in the db changes (images in WordPress are just like posts in the database)

    I hope that helps!

    Cheers,
    Ari.

  • octavian

    Thanks Ari

    I totally agree with what you say and i can see that in the "_postmeta" table there is the correct "_thumbnail_id" field with a corresponding id.

    However, this doesn't display the featured image and no image appears in the post editor where featured image should be.

    My thought is that there must be some link between the featured image and the db table missing, but I'm not sure where to look. I can only think that it must be a path somewhere, connected to the fact that the structure of where media files are held is different in mutli-site.

    Any ideas?

  • octavian

    Hello Jack

    Yes... I imported the content using the xml import and then changed the url of the media files in the database posts table from "files" to "wp-content/uploads".

    This worked fine for finding the post images, but seems to have lost contact with featured images.

    I've verified that all the images exist in the right place and that there is an image id in the postmeta table.

    Any ideas?

    Ian

  • Hoang Ngo

    Hi @octavian,

    The Feature Image, it is a "post", with the post_type is "attachment", it's also have the post_parent field value is the post you add this feature image.

    And the url of the feature image is in the postmeta table. The url is relative, so domain is not matter.

    So for a post have feature image, you will be need to check the relations

    1. Post need to have the postmeta with key = "_thumbnail_id", and the value is the feature image id.
    2. The feature image will need to have post_parent link back to the post, and it should have those meta:
    _wp_attached_file and _wp_attachment_metadata which contain correct data.

    Can you please check and make sure the feature image have valid attribute above ?

    Best Regards
    Hoang

  • octavian

    Hello Hoang

    I can confirm that posts have the postmeta with key = "_thumbnail_id", and the value is the feature image id.

    I can see that in the _posts table there is column for "post_type" and there are a number of the type attachment. Each of these has the correct complete url to the images in the column headed "guid". Next to this is a column headed "post_parent" and for each of these it is set to 0.

    In the "_postmeta" table both "_wp_attached_file" and "_wp_attachment_metadata" have valid post ids. The path in this table is a url from the media library folder.

    Some additional information... if I go to the original db in the mutlisite for this site... the "post_parent" column has the correct entries.

    Does this mean that the problem will be avoided by importing the two db tables and then changing the media folder url in the "_posts" table?

    Would it be better to migrate the multisites in this way?

    Thanks for your help so far.

    Ian

  • Hoang Ngo

    Hi @octavian,

    I can see that in the _posts table there is column for "post_type" and there are a number of the type attachment. Each of these has the correct complete url to the images in the column headed "guid". Next to this is a column headed "post_parent" and for each of these it is set to 0.

    I thinks this problem is here, the post_parent is 0, let me explain you the flow when render page.
    So you go to page, now wordpress will query all the attachments belong this page by the field post_parent, and if the post_parent is 0, so no attachments return => no feature image.

    I found this article, which is very useful
    https://managewp.com/split-multisite

    Summary, the steps are:
    1. Backup all your network
    2. Go to each site, and export the contents by wordpress export tool.
    3. Now you have all the exports, go to your new single site and import it one by one

    If you do this way, there's will no need to change anything in the database i think. Please try it and in the mean time, if possible could you enable support staff login in WPMU DEV dashboard > support > support access > grant access, please ?

    I will check if it have any potential issues might happend.

    Best Regards
    Hoang

  • octavian

    Hello Hoang

    I think that you're right with regard to the post_parent being the issue.

    I have read the article that you've mentioned and unfortunately the author has not completely tested the process and makes it out to be very simple. If you read the comments below the article, you will see that others have experienced problems with the method he recommends.

    The problem is that by simply exporting the XML file you do not take into account that the media library is in a different location on multi site and therefore when importing that url to the media library needs to be changed.

    Also this does not reliably import the images in the correct thumbnails etc. For this there is a plugin called "add to server" which works well.

    The method I have used so far has been to do the following:

    To export:

    1. backup multi site
    2. download "files" folder from the correct site id in "blogs.dir"
    3. download the theme
    4. list plugins being used
    5. install widget importer and exporter plugin on multi site
    6. export widget settings and export settings from plugins and themes where available.
    7. if domain is mapped, remove mapping and remove addon domain from cpanel.

    To import to single site and account:

    1. Create Cpanel account
    2. Install Wordpress
    3. increase memory size in config file if required
    4. upload the content of the "files" folder to "uploads"
    5. Install theme
    6. Install plugins
    7. Configure settings for plugins
    8. Import Wordpress XML file
    7. Restore widget settings
    8. Set permalinks and other worpress settings

    At this point the media files are usually missing, at this point I have gone into phpMyAdmin and altered the path in the _posts table using:

    UPDATE wp_posts SET post_content=(REPLACE (post_content, 'files','wp-content/uploads'));

    I've also found that it's possible to change the default media upload location, by editing the wp-config.php file located in the root directory of your WordPress installation. If you want upload directory to be wp-content/files then you will need to place the following code in wp-config.php

    define( 'UPLOADS', 'wp-content/'.'files' );

    If you want the upload directory to be outside wp-content, like http://www.example.com/files/ then you need to set upload path in wp-config.php like this:

    define( 'UPLOADS', ''.'files' );

    I've done this a number of times with various sites and the only issue is the missing featured image.

    It seems that other people have had the same issue, but no-one has come up with the solution. I think you're guidance has pointed to the cause, but I don't think that the correct information is being exported with the XML file and so the import won't work.

    I'll try with another site later and try importing the old tables to see if this solves the issue.

    Is there a way to check in the XML file if the parent_post ID is being included?

    Unfortunately, I can't give access to the multi site at present.

    Thanks
    Ian

  • octavian

    Hello Hoang

    In addition to the above, I've found that replacing the data in the "_posts" table for the new single site with the original data from the multisite install solves the problem.

    The url to the media library needs to be altered to match the single site structure ("wp-content/uploads" rather than "files").

    I'll do a complete migration of another site to check that the whole thing works as expected.

    Thanks
    Ian

  • Hoang Ngo

    Hi @octavian,

    I hope you are well today and I'm sorry because the method i sent not work.

    Is there a way to check in the XML file if the parent_post ID is being included?

    Just need to open that xml, and search the "post_parent", it should have the parent id.

    In addition to the above, I've found that replacing the data in the "_posts" table for the new single site with the original data from the multisite install solves the problem.

    Glad to hear this, but when you replace the data, i think we should take eyes on the ID, make sure it will smaller than the database auto increment.

    Please keep me update Ian, and many thanks for the very detail guide, this soon will be the first solution for this case in the internet :smiley:.

    Best Regards,
    Hoang

  • octavian

    Hello Hoang

    Just to confirm that the post_parent id is included in the XML file, so seems to be being lost on the import and set to "0".

    The Wordpress import plugin shows an error when trying to import the attachments and fails to import them.

    It also seems like it's crucial to use the 'add from server' plugin to import everything into the media library in the right location.

    I need to do some more tests as it may be important to do everything in a particular order.

    Thanks
    Ian

  • octavian

    Hello Hoang

    I have done another test migrate and everything seems to be in the correct place. This was the order that I did it:

    upload files folder
    upload themes
    import wordpress xml without file attachments got message ‘failed to import media’
    Use add from server plugin to add to media library
    confirm images in media library
    no featured images showing on site
    no images showing on site
    import data from old db to posts table
    change url from files to wp-content/uploads

    I need to test this further, but would be happy to write a detailed guide on how to do it.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.