Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
If you're experiencing issues with the

get_terms

function returning an empty array for translated terms in a multilingual setup using WPML, consider following.

Solution:
Firstly, ensure you're using the correct syntax for the

get_terms

function. Since WordPress 4.5.0, taxonomies should be passed via the 'taxonomy' argument in the

$args

array. Here's an example of how to use it correctly:

$terms = get_terms( array(
    'taxonomy' => 'post_tag',
    'hide_empty' => false,
) );

Next, consider reviewing the following resources for additional guidance:

Also, take a look at the WPML Hooks Reference for additional hooks and examples that might be helpful, especially the

wpml_get_element_translations

hook.

If these suggestions do not resolve your issue, and you're not comfortable with custom coding, you might want to consider hiring a developer. You can find qualified contractors at https://wpml.org/contractors/.

Please note that the solution provided might be outdated or not applicable to your case. If the issue persists, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please don't hesitate to open a new support ticket with us.

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.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Waqas Bin Hasan 2 years, 9 months ago.

Assisted by: Waqas Bin Hasan.

Author Posts
April 7, 2022 at 9:59 am #10971517

omerP

I have used following function in my code. It is working in default language. but not working in translated language. In translated language it is returning empty array.

$terms = get_terms( 'grade', [
'hide_empty' => true,
'orderby' => 'meta_value_num',
'meta_key' => 'sort_order',
'order' => 'ASC',
] );

Let us know what we need to change for getting all terms in translated language.

April 8, 2022 at 6:04 pm #10983825

Waqas Bin Hasan
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting the support.

We do not normally offer support for custom code, but I can suggest you a few pointers:

1. Since WordPress 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array, for example:

$terms = get_terms( array(
    'taxonomy' => 'post_tag',
    'hide_empty' => false,
) );

Please see https://developer.wordpress.org/reference/functions/get_terms/ for details.

2. Please see if any of the followings are helpful:
- https://wpml.org/forums/topic/get-translated-terms-with-get_the_terms/#post-6482389
- https://wpml.org/forums/topic/how-to-correlate-translated-and-base-language-terms/#post-6272817

3. Please see WPML Hooks Reference at https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/#hook-1215380 for details, specially wpml_get_element_translations. In this reference you may find several useful hooks and examples about how to use them. I hope you may find one to best suit your needs.

Lastly, if you would want to contact a developer, please see https://wpml.org/contractors/.

Have a great weekend!