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
April 5, 2023 at 2:34 am #13405233

Long Nguyen
Supporter

Languages: English (English )

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

Hi,

Let me know if it helps.

Thanks.

April 8, 2023 at 8:57 am #13431083

John-Pierre Cornelissen

Still working on it.

April 9, 2023 at 2:17 pm #13434257

Long Nguyen
Supporter

Languages: English (English )

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

Hi,

Take your time and you can reply to this ticket in next few days or create another ticket whenever needed.

Thanks.

April 16, 2023 at 9:34 am #13481049

John-Pierre Cornelissen

pls keep open

April 25, 2023 at 8:26 am #13531593

John-Pierre Cornelissen

Hi, here is an update

Your query doesn't work correctly. It does remove the duplicate entries, but it doesn't take into account that images have been used. It's ok for pages where WP/theme directly links to the image file, but it breaks images in galleries that link to the entry ID.

You also advised the media cleaner plugin. That also doesn't work. The media library shows 6 entries pointing to the exact same image files. So one from the original uploaded file and 5 from the copies that WPML made for the different languages. The media cleaner plugin does find the copies, but when I use the plugin to delete them, it also deletes the actual files. This leaves one entry in the media library that points to an image file that is deleted and it breaks every page where that image has been used on the website.

You really have to come with a better solution to fix the mess that was left behind by WPML.

April 25, 2023 at 9:18 am #13532063

Long Nguyen
Supporter

Languages: English (English )

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

Hi,

Thank you for your feedback.

>> It does remove the duplicate entries, but it doesn't take into account that images have been used.
Yes, it's not possible to cover everything that used the translation image (entry ID) on your site, even if you delete that translation image with WPML (remove language).

>> It's ok for pages where WP/theme directly links to the image file, but it breaks images in galleries that link to the entry ID.
The translation image (entry ID) is only used on the translation post/page, so does that mean the translation post/page is not deleted also?
Then you will need to delete the translation post/page along with the translation image. If you still use the translation image for the new posts after deleting WPML, I'm afraid that there is no way to remove that entry ID associated with the post.

In general, I think it's not a mess from WPML because we already have a notification message before resetting WPML in WPML > Support > Troubleshooting > Reset.

"The 'Reset' action will deactivate the WPML plugin after it deletes the WPML tables (tables with the 'icl_' prefix) from the database. The action will NOT delete any content (posts, taxonomy terms etc.). It only affects translation and language information that WPML associates with each content type."

Thanks.

April 25, 2023 at 10:12 am #13532455

John-Pierre Cornelissen

Yes the Image ID was originally used in translated posts/pages, but after removing WPML, the media library shows 6 entries for the same image. You don't see what the original entry is and what entries were created by WPML. So when you pick an image in a new post/page, you don't know if it's the original or or a copy.

And yes it is a mess caused by WPML because you don't offer a way to remove the translated media items. The only thing the reset message says is that it doesn't delete any content. It doesn't tell you how you can remove the translated content and it doesn't warn you what happens with the media library.

As for the content, before removing and resetting WPML I manually deleted the translated posts/pages, because the posts/pages list has a filter at the top where you can filter by language, so you can easily delete the translations. Such filter is not available in the media library. And even if it was, you would probably not think about using it before removing WPML.

The mess is now that I have 5 copies of each image in the media library without any option to remove the copies, because the database does not contain any marker that indicates that it is a WPML media record.

April 26, 2023 at 1:32 am #13537513

Long Nguyen
Supporter

Languages: English (English )

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

Hi,

Thank you for your feedback.

The image (media) is actually a standard post type of WordPress and an image is also a post content, please read more here https://developer.wordpress.org/themes/basics/post-types/
You can delete the image in second languages manually by switching language with the language switcher at the topbar menu in the admin area.

And we also have documentation about deleting content when removing a language https://wpml.org/faq/how-to-completely-remove-a-language-from-your-site/

I will inform our development team to consider adding a link to the documentation in the Reset section to suggest deleting content in the second language.

Thanks.

April 26, 2023 at 1:44 pm #13541631

John-Pierre Cornelissen

You are repeating the same message again, but it doesn't help me fix the duplicate image issue.

It looks like the query you gave to delete the duplicate records is the only way to get rid of them. Since this is now going on for 4 weeks and you didn't come up with a better solution, I used this query. As expected, it left me with several broken images on the website.

The image (media) is actually a standard post type of WordPress and an image is also a post content, please read more here https://developer.wordpress.org/themes/basics/post-types/ You can delete the image in second languages manually by switching language with the language switcher at the topbar menu in the admin area.

That only works if WPML is still active, not after a reset which is the whole issue of this ticket!

And we also have documentation about deleting content when removing a language https://wpml.org/faq/how-to-completely-remove-a-language-from-your-site/

That's only available since version 4.5.9 which wasn't released yet when I deactivated and reset WPML.

I will inform our development team to consider adding a link to the documentation in the Reset section to suggest deleting content in the second language.

The current reset option is destructive and leaves you with a big mess that's almost impossible to get rid off. The message that explains it is ambiguous.

Also, if you want to remove WPML, you want this to be as easy as possible. It's too many steps if you first have to go to another place to disable all languages, then delete the content from these languages and then use reset.

So in my opinion the reset option should do it all and give a choice to:
1. Reset WPML and delete translated content
2. Reset WPML and keep translated content

Thanks
JP

April 27, 2023 at 1:42 am #13545611

Long Nguyen
Supporter

Languages: English (English )

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

Hi,

Thank you for your feedback.

It looks like the query you gave to delete the duplicate records is the only way to get rid of them.

Yes, exactly. If you take a look at the table wp_posts, you can see WPML does not add any extra columns to the standard table of WordPress, thus there is no information about language in the table where the WordPress content stored (posts, pages, media, CPT ...).

it left me with several broken images on the website

It's not possible to fix an issue from a half year ago and without any backup file while you are still working on the site. If you see there is something wrong, you should create a new forum ticket or a chat session to ask for help from WPML support at that time. I understand this situation but please bear with us, the workaround here is to delete the duplicate images in the database, there is nothing additional information about WPML here.

So in my opinion the reset option should do it all and give a choice to:
1. Reset WPML and delete translated content
2. Reset WPML and keep translated content

It could be a nice feature request. I will forward it to our development team to consider adding it to the development queue.

Thanks and have a good day.