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 1 reply, has 2 voices.

Last updated by Riffaz 7 months, 1 week ago.

Assigned support staff: Riffaz.

Author Posts
March 11, 2019 at 3:22 am #3307529

alanM-6

Tell us what you are trying to do?
Use the get_categories() function to get a list of the categories in the current language (the get_categories function is being called from functions.php)

Is there any documentation that you are following?
no

Is there a similar example that we can see?
Currently get_categories() returns all categories from all languages.

What is the link to your site?
hidden link
(see 'select specialty dropdown)

March 11, 2019 at 6:35 am #3307929

Riffaz
Supporter

Languages: English (English )

Timezone: Asia/Colombo (GMT+05:30)

Hi,

Thank you for contacting WPML support.

You could try this: https://wpml.org/wpml-hook/wpml_switch_language/

Just use this action before your get_categories and this will switch language to the given one and get_categories will return results in only one language.

If you use it, don't forget to switch back to original language after getting categories. You should store original language before whole process and then use it. To obtain this language you can use filter https://wpml.org/wpml-hook/wpml_current_language/

----------

If this does not help and get_categories would still retrun all language results, you could try to post-process list of categories: iterate all categories, check its language with one of those filters:
https://wpml.org/wpml-hook/wpml_element_language_details/
https://wpml.org/wpml-hook/wpml_element_language_code/

and compare if this is what you want.

I hope this helps you ???? In case if you want to know whole WPML api hooks, here it is:
https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/

Regards,
Riffaz.