We use the following shortcode on several places on our website: [wpv-post-body view_template="my-layout" id="123"]
We run into a problem, as we use multiple languages. When duplicating pages from our main language to others, the content templates correctly changes the language, but the content not (as it is loaded from the original language).
So far I don't see that there is a workaround that enables us to use the same ID in different languages, right?
Therefore I thought we could filter the shortcode: instead of using the ID, we could use the name (=post title). The name is always the same in all languages. Can I do that with that shortcode?
Just in case it wasn't clear: we use always the same content template but change the ID according to our needs. Therefore we can't hardcode it.
Now when I'm thinking about it, could it be possible to create a view with this content template, define a filter parameter in the query that checks the post title for the string I define in the shortcode?
1. First and simpler option is the "view" option, as you noted. You can make your content template part of a view that is set to show only one post, with a "Query Filter" set to search for post titles, through a shortcode attribute.
( screenshot: hidden link )
Note: If any two posts have very similar or partially matching titles, this option can result in showing a different post than the intended one.
2. An alternative is to use "wpml_object_id" filter, to generate the "wpv-post-body" shortcode, through a custom registered shortcode: https://wpml.org/wpml-hook/wpml_object_id/
The benefit of "wpml_object_id" is that it accepts an ID and automatically returns the ID of relevant posts in the current or the specified language.
For a more personalized assistance around the custom programming, you can also consider hiring a professional from our list of recommended contractors: https://toolset.com/contractors/