• Resolved Daniel Zimmermann

    (@optimiertes)


    Hello Kevin,
    I am using WPML and have an English and German version of a page. On both pages I use the helpful shortcode to receive pro and contra votes.

    My goal is to have the votes counted together and not separate votes for the English and German version.

    Do you have a hint for me how to achieve this?

    Thank you,
    Dan

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Pixelbart

    (@pixelbart)

    @optimiertes

    Hello Dan,

    if WPML uses a separate post with its own ID for each translation, this is a bit difficult.

    https://gist.github.com/pixelbart/26377d738ff2ed8b38d1b9cfae026977

    Unfortunately I am not familiar with WPML and don’t know if the variant used will find the original ID of the post. Also I have not tested the code I am sharing with you here.

    Stay healthy!

    Thread Starter Daniel Zimmermann

    (@optimiertes)

    Hello Kevin,
    I truly appreciate all your effort to provide this snippet to me.
    Thank you very much!

    I implemented the new shortcode on my website, but it is not working as expected.

    Yes WPML is creating a new post for each translation, therefore each page ID is different.
    I thought a way to solve it to convert every Post ID to the Post ID of original (or main language) post.

    I tweaked your snippet for testing a bit to have the same static existing Post ID on each page the shortcode is implemented:

    $post_id = 137; //apply_filters( 'wpml_object_id', $post->ID, 'post' );

    The interesting thing is that indeed all the votes are counted to the “137” Page. However, only on the very “137” page count is also displayed.
    So it seems that the voting logic cares for the “post_id” attribute, but not the code that displays the votes of each post respectively.

    Is there a way to make the shortcode count AND display the votes to the “post_id” provided?

    Plugin Author Pixelbart

    (@pixelbart)

    @optimiertes

    If I understand you correctly, are you using the display for “number of votes” of Helpful?

    https://gist.github.com/pixelbart/26377d738ff2ed8b38d1b9cfae026977#file-functions-php-L22

    I just adjusted the gist for this. This might solve your problem. Actually the wpml_object_id should always be the ID of the parent.

    • This reply was modified 5 years, 6 months ago by Pixelbart.
    Thread Starter Daniel Zimmermann

    (@optimiertes)

    Perfect Kevin, this is exactly what was missing.

    One more thing:
    apply_filters( 'wpml_object_id', $post->ID, 'post', TRUE, 'de');

    The language code parameter should be a static value representing the default language (in my case ‘de’).

    Now it works! You are amazing!
    Danke dir!

    Plugin Author Pixelbart

    (@pixelbart)

    @optimiertes

    Super, freut mich zu hören! 🙂

    Dann bleib gesund und viel Spaß mit Helpful!

    LG Kevin

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Helpful and Multilanguage Pages’ is closed to new replies.