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
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.
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
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.