This user has no favorite topics.
Favorite Forum Topics
Forum Topics Created
| Status |
Topic
|
Supporter | Voices | Posts | Freshness |
|---|---|---|---|---|---|
|
All Featured Images are Lost
1
2
Started by: aaronM-20
in: English Support
Problem: function duplicate_featured_images_to_translations() {
// Ensure this runs only in the admin area
if (!is_admin()) {
error_log('Not in admin area. Exiting function.');
return;
}
// Get all posts of the custom post type 'automobile'
$args = array(
'post_type' => 'automobile',
'posts_per_page' => -1,
'post_status' => 'publish',
);
$automobiles = new WP_Query($args);
if ($automobiles->have_posts()) {
error_log('Found posts of type automobile.');
while ($automobiles->have_posts()) {
$automobiles->the_post();
$post_id = get_the_ID();
error_log("Processing post ID: $post_id");
// Get all translations for the current post
$trid = apply_filters('wpml_element_trid', null, $post_id, 'post_automobile');
if (!$trid) {
error_log("No TRID found for post ID: $post_id");
continue;
}
$translations = apply_filters('wpml_get_element_translations', null, $trid);
if (!$translations) {
error_log("No translations found for post ID: $post_id");
continue;
}
$update_original_post = false;
foreach ($translations as $lang => $translation) {
$translated_post_id = $translation->element_id;
error_log("Checking translation for language: $lang, post ID: $translated_post_id");
// Check if the translated post has a featured image
if (!has_post_thumbnail($translated_post_id)) {
error_log("No featured image found for translation post ID: $translated_post_id");
$update_original_post = true;
break;
}
}
if ($update_original_post) {
error_log("Updating original post ID: $post_id to duplicate media and featured image.");
// Enable the settings to duplicate media and featured images on the original post
update_post_meta($post_id, '_wpml_media_duplicate', 1);
update_post_meta($post_id, '_wpml_media_featured', 1);
// Update the original post to trigger the duplication
wp_update_post(array(
'ID' => $post_id,
'post_content' => get_post_field('post_content', $post_id) // Just update without changes to trigger duplication
));
} else {
error_log("No update needed for original post ID: $post_id");
}
}
} else {
error_log('No posts of type automobile found.');
}
// Reset Post Data
wp_reset_postdata();
}This script checks each post and its translations, and if the translation lacks a featured image, it updates the original post to enable media and image duplication. **** Important! Please make a full site backup (files and DB) before you proceed with those steps**** Please note that this solution might be irrelevant if it's outdated or not applicable to your case. If this doesn't resolve your issue, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If the problem persists, please open a new support ticket. |
|
2 | 23 | 1 year, 11 months ago | |
|
Fixing Partially Translated Posts
Started by: aaronM-20 in: English Support |
|
2 | 6 | 2 years ago | |
|
"Open in Translation Editor" Button Not Working
Started by: aaronM-20 in: English Support |
|
2 | 10 | 2 years ago |