Using rwmb_get_value on a multilingual website (WPML)

Support General Using rwmb_get_value on a multilingual website (WPML)Resolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #37999
    ArnoArno
    Participant

    Hello,

    My website has MetaBox and WPML installed, with English as the primary language and German as the secondary language.

    I have the ID of the German version of the post type "merchant". I thought I would be able to get a field value of that post with the below code. Both the post type and field are translatable in WPML, and have been translated.

    $merchant_name = rwmb_get_value( 'content_long_title', '', $postID );

    But that returns nothing.

    This returns the expected German value:

    $postIDde = apply_filters( 'wpml_object_id', $postID, 'merchant', false, 'de');
    $merchant_name = get_post_meta( $postIDde, 'content_long_title', true);

    This returns nothing either:

    $postIDde = apply_filters( 'wpml_object_id', $postID, 'merchant', false, 'de');
    $merchant_name = rwmb_get_value( 'content_long_title', '', $postIDde );

    Can rwmb_get_value not deal with fields that have been made translatable with WPML? If there is a way to make it work, please let me know.

    #38022
    Long NguyenLong Nguyen
    Moderator

    Hi Arno,

    I do not see any issue when using the helper function rwmb_get_value() to display the translation field value on the frontend. But you can try to use the helper function rwmb_meta() in this case.

    See how it works on my demo site https://monosnap.com/file/Tbj5Hc91OgrVMusrk2BW7oQ4WzNCKb

    Steps to reproduce:
    - Go to WPML > Settings > Enable translate for the field content_long_title
    - Translate the post and field value
    - Add this code to the post template to display the field value

    $content_long_title = rwmb_meta( 'content_long_title' );
    echo 'content_long_title: ' . $content_long_title;
    #38028
    ArnoArno
    Participant

    Hi Long,

    Great, rwmb_meta works for me. I can pass the original post ID, so I don't need to request the translated post ID first. That's one less line of code 🙂 I'm not sure why rwmb_get_value() only works for English in my case.

    Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.