We are using WPML for our multilingual site and we have set up a one to many relationship like this: hidden link
Now when we try to list product_update via WP_Query as per the following code for the respective language it's showing all posts from all languages:
Here is the piece of code
$updates_query = new WP_Query( array( 'post_type' => 'update', 'post_status' => 'publish', 'posts_per_page' => 10, 'order' => 'DESC', 'orderby' => 'date', 'toolset_relationships' => array( 'role' => 'child', 'related_to' => get_the_ID() , 'relationship' => 'product_update' ) ) );
We also tried toolset_get_related_posts() function but that is returning blank data. We have used it like this
toolset_get_related_posts( get_the_ID(), 'product_update', 'child' );
It'd be great if you could help us with this.
Regards,
Nick
You should add the query_by_role argument to your main relationship query array, and as a test, use a known campaign ID:
toolset_get_related_posts(
12345,
'product_update',
[
'query_by_role' => 'parent',
'limit' => 10,
'offset' => 0,
'args' => [],
'role_to_return' => 'other'
]
);
Beyond that, I would need to know more about the WPML side of things. Are you querying a primary language campaign? What is the translation setting for these post types?
Hi Christian,
Thank you for your help, that's really helpful but unfortunately, it's not working for us and we need further assistance.
Actually we have set up 2 languages on our site -> /de and /en
When the code runs it dynamically inserts a post in the "update" post type and from that inserted id we connect that post to the product post type with this code
toolset_connect_posts( 'product_update', $product_id, $update_id );
But we can't connect the post to both languages.
Do you think this code needs some language parameter to pass to connect both languages with the update?
Thanks,
Nick
Do you think this code needs some language parameter to pass to connect both languages with the update?
No, there is currently no language parameter because post relationships are defined between primary language posts only. No direct post relationship is maintained between secondary language posts in the current system. Secondary language relationships are inferred based on the post relationship in the primary language content and the translation setting and translation status of the two primary language posts. The obvious limitation here is in multilingual sites with post relationships where User content is submitted with Forms, because it means that the content must first be submitted in the primary language no matter what is the language of the User. Our developers are currently working out how to allow content to be created in a secondary language first and still accommodate post relationships, but for now if you want to use post relationships the content must be created programmatically in the primary language, created in the primary language in wp-admin, or submitted in Forms in the primary language of the site.
More important information about translating and related content:
https://toolset.com/documentation/translating-sites-built-with-toolset/translating-related-content/
Hi Christian,
Thank you for your response on the ticket!
So what we need is not possible with the current version of the plugin, right?
Because we want to assign separate posts under each language.
Here's an example:
Suppose having a post called "Post A" with English and "Beitrag A." with German version of languages
Now we have relationship with toolset and under that toolset there is another post type called "Updates"
And update having posts called "Post Update A, Post Update B" for English and "Nach dem Update A. , Nach dem Update B" under German
Now we want to assign "Post Update A, Post Update B" to "Post A" in English and "Nach dem Update A. , Nach dem Update B" to "Beitrag A." in German
So I feel that's not possible with your recent comment if you have any idea how can I achieve that then please. let me know
Thank you!
So what we need is not possible with the current version of the plugin, right?
I'm not sure this is true. Your explanation didn't include anything that seems inherently impossible. As I understand it, as long as content exists in the primary language and you manage the post relationships for that content in the primary language, you should be able to assign existing secondary language content as the translations of those primary language posts, and the post relationships from the primary language will be inherited by the secondary language. Your site's primary language is German, right? So in other words the relationship between Beitrag A and Nach dem Update A will be inherited by Post A and Post Update A, as long as Post A is assigned as the translation of Beitrag A and Post Update A is assigned as the translation of Nach dem Update A. What will not work is if you have Post Update C in English and expect to be able to connect it to Post A without having Nach dem Update C in German, because the post relationship between Nach dem Update C and Beitrag A must be managed in the primary language. It is not possible to manage that in English.
Normally translated content (secondary language content) is submitted via the WPML translation manager process, creating a separate post in a secondary language and linked to the primary language content in the database. In your case it sounds like the secondary language content is created or generated some other way. You need a way to connect that arbitrary secondary language post as the translation of the primary language post. It's possible with custom code. Examples:
https://wpml.org/forums/topic/set-post-translation-with-a-php-script/
https://wpml.org/forums/topic/post-translations-via-php/
Hi Christian,
Thank you for your response!
I will try some code snippet from your provided 2 links and let you know, but below further comment might help you the understand it better
Our site primary language is English
As per your comment, we are not able to connect the posts that way. I should mention that we want to connect different posts not translated posts.
Means that "Post A" in English will be connected with different posts from "Updates" like "Post Update A" and "Post Update B"
In some cases, they won't be translated in German and in some cases, they will be translated
And "Beitrag A." in German will be connected with different posts from "Nach dem Update C." In our case, we need to connect some German post updates to German posts and English posts to English posts.
At the moment we are not able to connect the posts that way. If there's any script or guideline to achieve this then please let us know so we can implement it.
I hope this makes sense
Thank you for your help!
Regards,
Nicholas
Okay if you're trying to relate German content to other German content using post relationships, but there is no English language content that is a translated version of that German content, that is not possible. All post relationships must be managed in the primary language. That's the main limitation right now.
Ok got it.
Thanks for your help, Christian.