Skip Navigation

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

Problem:
I used this SQL query to change the post_type of a bunch of posts:

UPDATE `wp_posts` SET `post_type` = 'post' WHERE `post_type` = 'news';

In essence, I wanted my "news" CPT to no longer be a CPT, but instead, to be regular posts. Most (all?) of these "news" posts have translations.

If I deactivate WPML, I see all the converted posts on /wp-admin/edit.php and on the front-end of the site.

If I activate WPML, the ex-CPT posts no longer appear on edit.php nor on the front-end.

I suppose I need to modify something else in the DB, but I've poked around all over the place, and I can't find what I need to modify. Can you assist? Note that I am currently testing on our Development site but intend to do the same on the Production site.

Solution:
As you mentioned, the issue you're facing happens because WPML has specific tables that store information about post translations(https://wpml.org/documentation/support/wpml-tables/#language-information-and-translations).

When you changed the post_type in the wp_posts table, the metadata in WPML's tables still pointed to the old "news" post type, which is causing the discrepancy.

Here's how we can address this:

- Backup your database. This ensures you can revert changes if anything goes awry.

- Update the wp_icl_translations table in your database to reflect the change you made. In essence, you'll be telling WPML that these posts are now standard posts, not the "news" CPT. This code is an example of how you could handle such change(Please note: the code provided is to be used as an informational one. remember that custom coding is out of the scope of our support so we can't create, debug or modify code for you and it's your responsibility to maintain it. we hope the one we used as an example could point you in the right direction):

UPDATE `wp_icl_translations` 
SET `element_type` = 'post_post'
WHERE `element_type` = 'post_news';

-After updating the database, refresh your permalink settings in WordPress. This often resolves odd behaviors after changing post types.

Once these changes are made, your posts should appear correctly both in the admin area and on the front-end, even with WPML activated.

Relevant Documentation:
https://wpml.org/documentation/support/wpml-tables/

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 1 reply, has 2 voices.

Last updated by Mateus Getulio 1 year, 8 months ago.

Assisted by: Mateus Getulio.

Author Posts
August 16, 2023 at 8:56 pm #14241375

guillaumeC-30

Hi! I used this SQL query to change the post_type of a bunch of posts:

UPDATE `wp_posts` SET `post_type` = 'post' WHERE `post_type` = 'news';

In essence, I wanted my "news" CPT to no longer be a CPT, but instead, to be regular posts. Most (all?) of these "news" posts have translations.

If I deactivate WPML, I see all the converted posts on /wp-admin/edit.php and on the front-end of the site.

If I activate WPML, the ex-CPT posts no longer appear on edit.php nor on the front-end.

I suppose I need to modify something else in the DB, but I've poked around all over the place, and I can't find what I need to modify. Can you assist? Note that I am currently testing on our Development site but intend to do the same on the Production site.

August 17, 2023 at 6:17 pm #14248335

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hey there,

Thank you for contacting us.

As you mentioned, the issue you're facing happens because WPML has specific tables that store information about post translations(https://wpml.org/documentation/support/wpml-tables/#language-information-and-translations).

When you changed the post_type in the wp_posts table, the metadata in WPML's tables still pointed to the old "news" post type, which is causing the discrepancy.

Here's how we can address this:

- Backup your database. This ensures you can revert changes if anything goes awry.

- Update the wp_icl_translations table in your database to reflect the change you made. In essence, you'll be telling WPML that these posts are now standard posts, not the "news" CPT. This code is an example of how you could handle such change(Please note: the code provided is to be used as an informational one. remember that custom coding is out of the scope of our support so we can't create, debug or modify code for you and it's your responsibility to maintain it. we hope the one we used as an example could point you in the right direction):

UPDATE `wp_icl_translations` 
SET `element_type` = 'post_post' 
WHERE `element_type` = 'post_news';

-After updating the database, refresh your permalink settings in WordPress. This often resolves odd behaviors after changing post types.

Once these changes are made, your posts should appear correctly both in the admin area and on the front-end, even with WPML activated.

It's good to hear that you're currently testing on a development site. Always ensure everything works smoothly on the development site before making changes to your production site.

Please test it and let us know how that goes

Best regards,
Mateus

August 17, 2023 at 8:28 pm #14248703

guillaumeC-30

That worked, exactly what I needed. Thanks!