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 9 replies, has 2 voices.
Last updated by Radu 4 years, 5 months ago.
Assisted by: Radu.
Author | Posts |
---|---|
June 26, 2020 at 10:42 am #6460827 | |
j.p.d |
Hi there, I'm, trying to get translated terms with get_the_terms(); I do not get any results on the front-end, though I have translated the terms in WPML -> Taxonomy Translation. The result in the second language is just blank. I tried several (5?!) "solutions" from the forum but I can't get it to work. This is the code currently have hidden link Here you can see I have translated the terms: hidden link Can you assist me on this one? Thanks in advance. |
June 29, 2020 at 10:03 am #6474491 | |
Radu |
Hey there, Thank you for reaching out to the WPML support! As I can see, you're using the ID as the first parameter for the get_the_terms function. In this case, I think that you should use this WPML hook: and get the ID of the translated post. Once you did this, try to get the terms using the new ID. Can you give this a try and tell me how it goes, please? Thanks, |
June 29, 2020 at 2:04 pm #6477601 | |
j.p.d |
Hi Radu, Thank you for your reply. Honestly, I have no idea how to implement that example / hook. Tried a couple of things without a result.. Really appreciated. Thanks in advance. |
June 30, 2020 at 7:14 am #6482389 | |
Radu |
Hey Justin, You can try to replace this line: $terms = get_the_terms( $post->ID, 'ta_type' ); with this code: $current_ID = apply_filters( 'wpml_object_id', $post->ID, 'ta_type' ); $terms = get_the_terms( $current_ID, 'ta_type' ); Also, you need to check what's the value of the $post->ID variable too, and see what's the value that's returning both in the original and translated page. This way you might be able to identify the ID that's used and see why the returned terms are not correct. Thanks, |
June 30, 2020 at 9:37 am #6484277 | |
j.p.d |
Hi Radu, Thanks again for your response. Though I think something is not working correctly since the posts aren't translated, only the terms. Those posts cannot be translated since they are automatically generated. I have translated the terms, not the posts. The settings of the posts are set to "Not translatable". Unfortunately your code doesn't change anything. Any idea? Thanks in advance. |
July 1, 2020 at 10:06 am #6493561 | |
Radu |
Hey Justin, I'm sorry but I don't understand what do you mean by automatically generated posts. I just want to understand what you're trying to do so I can tell you for sure whether this can be done or not. Thanks, |
July 1, 2020 at 2:30 pm #6496659 | |
j.p.d |
Hi Radu, I'm sorry I wasn't too clear about this matter. It's like this:
The reason the posts are set to "Not translatable" is because these posts are automatically generated when a user did a transaction on the website. That post doesn't need to be translated, but the 'term' is like "Bought" or "Sold" or "Refund". Which needs to be translated in different languages. Hope I gave you enough information. Kind regards, |
July 2, 2020 at 11:20 am #6503351 | |
Radu |
Hey Justin, As long as the transaction posts are not translated, this means that all of them will be assigned to the original language. In this case, the terms won't be translated. In order to have translated terms, you need to have a translated post. This way you'll know which terms should be displayed (the one from the original language or the translated ones). Also, can you tell me how these transactions are created? Are these a part of a plugin? Maybe I can think of a workaround to apply in this case. Thanks, |
July 6, 2020 at 9:10 am #6528485 | |
j.p.d |
Hi Radu, Your time is appreciated! Isn't is possible to switch to a language (which is active?) to get a translated term? On the forums I saw possibilities to switch to a specific / active language to get something in a language. If that is possible, isn't it possible to get terms of a post in a specific or active language? The transactions are generated by custom code, created by our backend developer. But the post is created only in the default language (English). But the terms are translated. Thanks in advance. |
July 7, 2020 at 10:26 am #6537827 | |
Radu |
Hey Justin, For now, the only hook that you can use for changing the language is this one: However, as you can see, you need to use it only with the pre_get_posts WordPress hook. Thanks, |