0

我使用 WPML 翻译了一篇文章。
问题是它不会在翻译后的帖子中添加特色图片。
使用 WPML 媒体翻译复制图像占用的尺寸太大,
因此我想将不重复的特色图像添加到翻译后的帖子(wordpress)中。
你能告诉我如何解决这个问题吗?

谢谢你。

4

1 回答 1

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' );
   
    }
   
}
于 2021-07-01T01:34:01.063 回答