Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 4 replies, has 2 voices.

Last updated by Dražen 4 years, 10 months ago.

Assisted by: Dražen.

Author Posts
February 9, 2021 at 4:07 pm #8044091

mathiasD-7

Dear,

I am using the plugin 'Ultimate Blocks' to create reusable blocks for our wordpress website.
For Translating I use WPML.

I've translated the reusable blocks, and it works fine, when I just use that reusable block in a page.

The problem is, I want to use the reusable block in the footer (hereunder you can find the code I am using for that).

<?php
// get reusable gutenberg block:
$gblock = get_post( 87647 );
echo apply_filters( 'the_content', $gblock->post_content );
?>

The reusable block is showing, but not changing language (always shows in the default language).

Any idea on how to resolve this?

Thank you in advance

February 10, 2021 at 8:02 am #8048737

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello!

Welcome to WPML Support.

In your code, You are using a fixed ID (87647), which is probably the default language post. You need to get translated post ID also. For this, you must use the "wpml_object_id" hook to know the translated page ID programmatically.

Info: https://wpml.org/wpml-hook/wpml_object_id/

Example tickets:
- https://wpml.org/forums/topic/get-post-id/#post-980387
- https://wpml.org/forums/topic/get_post-of-current-language/#post-5462617

Kind regards,
Drazen

February 11, 2021 at 9:57 am #8059511

mathiasD-7

Dear Drazen,

First of all, thank you for your reply.

This is what I am trying now (unfortunatelly, it's not solved yet):

<?php
$correct_id = apply_filters( 'wpml_object_id', 87647, 'post', true );
$gblock = get_post($correct_id);
$content = apply_filters('the_content', $gblock->post_content);
echo $content;
?>

Any idea what I do wrong? Thank you in advance

February 11, 2021 at 12:29 pm #8061311

mathiasD-7

somehow it suddenly started working (not sure what I changed though)

February 11, 2021 at 2:08 pm #8062145

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

the shared code should work, and glad to hear your issue is now solved.

I suggest we close this ticket if no any other doubts.

I hope I was helpful. Don't hesitate to ask if you find any problem in the future, I'll gladly help you.

Regards,
Drazen