This thread is resolved. Here is a description of the problem and solution.
Problem:
The client has a custom post type called 'resources' with an accompanying custom Gutenberg block called 'resource feed'. This block is dynamic and displays data from entries in the feed. However, it does not display different content based on the selected language, showing the same content across all languages.
Solution:
We recommend using the
wpml_object_id
hook to ensure that the
$post_id
refers to the translated post in the currently active language. Here is how you can implement it:
// will return the post ID in the current language for post ID 1 echo apply_filters( 'wpml_object_id', 1, 'post' ); // will return the category ID in the current language for category ID 4. If the translation is missing it will return the original (here: category ID 4) echo apply_filters( 'wpml_object_id', 4, 'category', TRUE ); // will return the German attachment ID for attachment ID 25. If the translation is missing it will return NULL echo apply_filters( 'wpml_object_id', 25, 'attachment', FALSE, 'de' );
Ensure that the post has an existing translation. For further guidance, refer to the wpml_object_id documentation and the full list of WPML hooks at WPML hooks reference.
If this solution does not resolve your issue or seems outdated, please check related known issues at https://wpml.org/known-issues/, verify the version of the permanent fix, and confirm that you have installed the latest versions of themes and plugins. We highly recommend opening a new support ticket for further assistance at WPML support forum.
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 3 replies, has 0 voices.
Last updated by 5 days, 13 hours ago.
Assisted by: Andrey.