ข้ามไปยังเนื้อหาหลัก ข้ามไปยังแถบด้านข้าง

Waiting for author

Topic Tags: Compatibility

Overview of the issue

When using Meta Box with WPML, the ‘Post’ relationship field defined via Meta Box is not automatically populated with translated posts IDs, leaving the translated post without a valid relationship.

Workaround

Please, make sure of having a full site backup of your site before proceeding.

  • Add the following code to your theme’s functions.php file.
    add_filter( 'rwmb_meta', 'compsupp_8073_translate_parent_post_id', 10, 4 );
    function compsupp_8073_translate_parent_post_id( $value, $key, $args, $post_id ) {
        if ( $key === 'parent_post' && ! empty( $value ) && is_numeric( $value ) ) {
            $current_lang = apply_filters( 'wpml_current_language', null );
            $value = apply_filters( 'wpml_object_id', $value, 'parent-post', true, $current_lang );
        }
        return $value;
    }
            
  • Replace 'parent_post' with the actual Meta Box field name used for your relationship.

แสดงความคิดเห็น

โปรดอยู่ในหัวข้อและให้ความเคารพผู้อื่น หากคุณต้องการความช่วยเหลือในประเด็นที่ไม่เกี่ยวข้องกับโพสต์นี้ ให้ใช้ฟอรัมสนับสนุนของเราเพื่อเริ่มการแชทหรือส่งตั๋ว.

คุณสามารถใช้แท็กเหล่านี้:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>