Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client stopped using WPML and encountered an issue with a large number of duplicated images in the media library, even after using the reset option to delete the icl tables.
Solution:
We recommend trying the following SQL query on a staging site to remove duplicate images:

DELETE p1
FROM wp_posts p1, wp_posts p2
WHERE p1.guid = p2.guid AND p1.ID > p2.ID AND p2.post_type = 'attachment'

It is crucial to back up the database and website before executing this query.
Alternatively, the client can use the Media Cleaner plugin to clean up the media library.
We also informed the client that WPML 4.6.3 was released recently and advised checking the changelog for more details.

Please note that this solution might be irrelevant if it's outdated or not applicable to your case. If the issue persists, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If necessary, please open a new support ticket for further assistance.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 24 replies, has 3 voices.

Last updated by Long Nguyen 1 year, 7 months ago.

Assisted by: Long Nguyen.

Author Posts
March 29, 2023 at 10:17 am #13356621

John-Pierre Cornelissen

Hello,

I stopped using WPML on a website and now I have a huge load of duplicated images in the media library (see attached).

I found this ticket https://wpml.org/forums/topic/stopped-using-wpml-now-the-media-library-has-duplicate-images/

The icl tables were still there so I reïnstalled WPML, then used the reset option to delete them. That worked, but the media library is still full of duplicate images.

Now I don't think I can use the script of that support ticket, because it uses the icl tables and that are gone now.

How to fix this?

Thanks
JP

media.jpg
March 29, 2023 at 2:59 pm #13359699

Sumit
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

Thank you for contacting the support forum.
Before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.

I hope you took a backup before resetting WPML.
The script was useful in the previous version of WPML since WPML 4.5.9 we have the option to remove content including media.

You need to activate the WPML and then deactivate the language and delete language data. Once all languages except primary are removed you can reset the WPML from WPML > Support > Troubleshooting.

Please follow the guide https://wpml.org/faq/how-to-completely-remove-a-language-from-your-site/

Thanks

March 29, 2023 at 4:14 pm #13360347

John-Pierre Cornelissen

Hi and thank you for your reply.

If there is an option now to remove content including media, why did it not also remove the media entries when I used the reset option. Reset is advised when you want to disable and remove WPML. It would be logical it would remove all wpml related data without leaving alienated records in standard database tables.

I do have a backup, but things have been changed since then. So I can't restore that full database. The only thing I could try is to restore the icl tables only.

How to proceed now?

March 30, 2023 at 7:37 am #13363765

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi John,

Thank you for contacting WPML support, I'd be happy to help you with this issue.

>> why did it not also remove the media entries when I used the reset option.
Before resetting WPML, there is also a notice message about "The action will NOT delete any content (posts, taxonomy terms etc.)". That means all translation entries: posts, terms, media ... are not deleted from the database. The deletion is the WPML tables which connect them to the second languages.
You can read more on the documentation https://wpml.org/faq/how-wpml-reset-works/
https://wpml.org/documentation/support/wpml-tables/

>> I do have a backup, but things have been changed since then. So I can't restore that full database.
If you have a backup file, you can try to restore it on a staging site then delete second languages, import the new changes to the staging site and move all data to the live site. It may take some hours or days to do that. I think it is the best way we can do at this time.

I hope I was helpful. Don't hesitate to ask if you find any problem along the way, I'll gladly help you.

March 30, 2023 at 9:10 am #13364947

John-Pierre Cornelissen

Thanks. Don't you have a database query to remove the duplicate media records? So only keep the first one and trash the duplicates?

March 30, 2023 at 10:13 am #13365781

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

I'm afraid that there is no SQL query to delete the duplicate media entries after resetting WPML. You can try to import WPML tables to your site and run the snippet code (https://wpml.org/forums/topic/stopped-using-wpml-now-the-media-library-has-duplicate-images/#post-11936463) to delete the image.
Or try to use a third-party plugin to see if it helps
https://wordpress.org/plugins/media-deduper/
https://wordpress.org/plugins/delete-duplicate-posts/

Regards.

March 31, 2023 at 5:12 pm #13377973

John-Pierre Cornelissen

Thanks for the plugin suggestions.

I have restored a backup to see if I can follow the instructions to first remove the languages, but all icl tables in the backup are empty, except:

hws_icl_flags 65 rows
hws_icl_languages 65 rows
hws_icl_languages_translations 4.225 rows

And when I compare with the current version, these tables are missing from the backup
hws_icl_background_task
hws_icl_mo_files_domains
hws_icl_string_packages
hws_icl_string_pages
hws_icl_string_urls
hws_icl_translation_status

Looking back, I removed WPML from that site in September 2022 and I a almost sure I did use the reset option before deactivate it, and I might even have disabled languages first. In that case, WPML didn't properly clean up when it was disabled.

In any case, are these 3 tables with data enough to follow the current procedure and remove the duplicate images? Is there still a way to recognize the duplicate records? Do they have a language flag or a flag that indicates the records were created by WPML?

Thanks
JP

April 2, 2023 at 3:25 pm #13384805

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

WPML will not work properly with those 3 tables, the data on those tables are the standard info, they do not have any information about the post like language, translation ... The most important table is icl_translations which stores the info about the content type and translation in the second language. Please read more in the documentation https://wpml.org/documentation/support/wpml-tables/

If you are not able to accomplish this, I would recommend you contact one of our certified partners that will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Look forward to your reply.
Thanks

April 3, 2023 at 8:10 am #13387735

John-Pierre Cornelissen

Ok, so if I understand correctly, this basically means that:

- I correctly disabled WPML in the past
- WPML deleted all translation records from the tables
- but it did not delete the tables
- and it left a mess in the media library

And the only thing you can do now is advice me to purchase a license for a plugin to cleanup the mess WPML left or hire a contractor. Right?

April 3, 2023 at 9:46 am #13388527

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

- Deactivating or resetting WPML does not delete the translation content as you see in the box when clicking on reset WPML. The thing deleted is the connection between the content in the original language and second languages.

- Deactivating WPML does not delete WPML tables, I'm not sure if there are 3 tables left on your site but they do not store the info of the content in the original language and second languages.

- If you have a full backup of your site before resetting WPML, you can restore it, try to delete content in second languages first and reset WPML table then. If not, I'm afraid that, there is no SQL query to do that. You should use a third-party plugin or hire a contractor to help you in this case.

Thanks for your understanding and patience.

April 3, 2023 at 10:01 am #13388629

John-Pierre Cornelissen

WPML was deactived in September 2022 and the oldest backup I have is from December. That's the one I restored and in that backup, all WPML tables were empty except the tables I mentioned before.

I did not manually empty these tables, it must have happened by resetting WPML back in September before I deactivated WPML. At that time, I had version 4.6.3 installed.

In any case, it's WPML who messed up the media library, not me.

The way I see it is that there was a bug in that version that caused WPML to mess up the media library, and now you are telling me I have to pay for a plugin or contracter to fix it.

I believe WPML should have a script, query or plugin to fix the problems in the media that were created by WPML.

April 4, 2023 at 2:04 am #13395303

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

Just to clarify that, WPML does not mess up the media library. All the translation content: posts, pages, media, terms ... are not deleted after deactivating or resetting WPML. I don't think it was an issue because there is a notice about that before enabling an option to reset WPML in WPML > Support > Troubleshoot.

Otherwise, I'm asking our 2nd tier support about this case to get more advice and I will update you here when I have something to share.

Thanks for your patience.

April 4, 2023 at 9:09 am #13398035

John-Pierre Cornelissen

Well, everything is gone except for the duplicate records in the media library.
I don't know if or what notice there was half a year ago with version 4.6.3.

Much appreciated if you could ask advice from 2nd tier.

Thanks
JP

April 4, 2023 at 9:50 am #13398571

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

Thank you for your feedback.

Our 2nd tier support suggests you can try to use this SQL query on a staging site and see if it helps.

DELETE p1
FROM wp_posts p1, wp_posts p2
WHERE p1.guid = p2.guid AND p1.ID > p2.ID AND p2.post_type = 'attachment'

❌ IMPORTANT: Please backup your database and website before proceeding ❌

Or use this plugin https://wordpress.org/plugins/media-cleaner/

FYI, WPML 4.6.3 has been released a few days ago (March 27, 2023), not a half year ago. Please read the changelog here https://wpml.org/download/wpml-multilingual-cms/?section=changelog

Look forward to your reply.
Thanks

April 4, 2023 at 10:05 am #13398637

John-Pierre Cornelissen

Ok, will try and get back to you with an update.

Sorry, you're right about the version, it was v4.5.4 which I updated to v4.6.3 on 29 March 23