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
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
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
mathiasD-7
somehow it suddenly started working (not sure what I changed though)
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