Hi there
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?
Best,
Marcial
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?
Hi Marcial,
Thank you for contacting us and I'll be happy to assist.
Your understanding is correct and the "wpv-post-body" shortcode can only be used with the ID:
https://toolset.com/documentation/user-guides/views-shortcodes/#vf-153372
To make this work, you have a couple of options:
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: versteckter Link )
After that, you can pass on the title as an attribute of the view's "wpv-view" shortcode:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-view
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.
You'll find a good usage example of the code in this thread:
https://toolset.com/forums/topic/wpml-views/#post-508052
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/
I hope this helps.
regards,
Waqar
Hi Waqar
Thank you very much. I followed your explanation for step one. My shortcode now looks like this (and works!):
{!{wpv-view name='name-of-the-new-view' searchbyname='the-name-of-the-person-in-the-post-title'}!}
Best,
Marcial