WPML 如何添加特色图像而不重复到翻译后的帖子(wordpress)?

问题描述 投票:0回答:2

我使用 WPML 翻译了一篇文章。
问题是它没有在翻译后的帖子中添加特色图片。
使用 WPML 媒体转换复制图像会占用太多大小,
所以我想添加一个没有重复的特色图像到翻译后的帖子(wordpress)中。
您能让我知道如何解决这个问题吗?

谢谢你。

wordpress post wpml wordpress-featured-image
2个回答
1
投票

如果有人需要这个。
我使用下面的代码解决了这个问题。

add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
function my_duplicate_on_publish( $post_id ) {
    global $post;
    // don't save for autosave
    if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
        return $post_id;
    }
    // dont save for revisions
    if ( isset( $post->post_type ) && $post->post_type == 'revision' ) {
        return $post_id;
    }
    
    if ($post->post_type=='your-post-type') {
           
        //we need this to avoid recursion see add_action at the end
        remove_action( 'wp_insert_post', 'my_duplicate_on_publish' );
    
        // make duplicates if the post being saved
        // #1. itself is not a duplicate of another or
        // #2. does not already have translations
    
        $is_translated = apply_filters( 'wpml_element_has_translations', '', $post_id, $post->post_type );
    
        if ( !$is_translated ) {
            do_action( 'wpml_admin_make_post_duplicates', $post_id );
        }
    
       //must hook again - see remove_action further up
       add_action( 'wp_insert_post', 'my_duplicate_on_publish' );
   
    }
   
}

0
投票

您可以在翻译覆盖 wpml-config.xml 文件的帖子时复制特色图像:

<wpml-config>
    <custom-fields>
        <custom-field action="copy">_thumbnail_id</custom-field>
    </custom-fields>
</wpml-config>
© www.soinside.com 2019 - 2024. All rights reserved.