Skip Navigation

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 5 replies, has 2 voices.

Last updated by zsoltE-2 4 years, 8 months ago.

Assisted by: Marcos Vinicios Barreto.

Author Posts
August 8, 2019 at 3:06 pm #4364117

zsoltE-2

Hi. I would like to get all product categories regardles of its language.
WP_Term_Query( array( 'taxonomy'=>'product_cat'));

This will return only the product categories of the default language.

How can I get taxonomy of all languages?
Regards, Zsolt

August 8, 2019 at 5:06 pm #4364917

Marcos Vinicios Barreto

Hello,

Thank you for contacting WPML Support. Since WPML adds a filter to return only the taxonomy terms in the current language, you would need to temporary disable these filters when getting the terms values available in all the languages, here is a code you can try:

global $sitepress;
$taxonomy = 'your-taxonomy-slug';
if ( $sitepress ) {
    remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ) );
    remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ) );
    remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
    $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'fields' => 'id=>name' ) ); // Change the args accordingly
    add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 4 );
    add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 );
    add_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 );
}
else {
    $terms = get_terms( array( 'taxonomy' => $taxonomy, 'hide_empty' => false, 'fields' => 'id=>name' ) ); // Change the args accordingly
}

The code above is based on this ticket: https://wpml.org/forums/topic/get-all-terms-of-all-languages-outside-loop/ where another customer had a similiar request. Hope it helps, have a nice day.

August 9, 2019 at 2:57 pm #4371507

zsoltE-2

Hi again,
One more question:
How could I set the language of the WP_Term_Query. My site's default language is Hungarian, but I want a WP_Term_Query of English terms.
Is it possible?
Regards, Zsolt

August 9, 2019 at 6:33 pm #4372465

Marcos Vinicios Barreto

Hello,

Thank you for the updates. Please, refer to this ticket: https://wpml.org/forums/topic/how-to-filter-get_terms-function-my-own-language/ it deals with the same request as yours. Hope it helps, have a nice day.

August 10, 2019 at 2:15 am #4373577

zsoltE-2

Thanks

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.