Created
September 15, 2021 23:04
-
-
Save everaldomatias/642f131fe10a7b60ca261bb52eba790e to your computer and use it in GitHub Desktop.
Return all terms, of the all languages, when use WPML plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* | |
* Use this function when using the WPML plugin on your WordPress, | |
* to return all terms and all languages | |
* | |
* @author https://stackoverflow.com/users/2307600/alin-razvan | |
* @link https://stackoverflow.com/questions/66062846/wordpress-wpml-plugin-get-terms-returns-data-only-for-current-language-i-wan/#answer-66062847 | |
* @link https://developer.wordpress.org/reference/functions/get_terms/ | |
* @link https://wpml.org/forums/topic/remove-get_terms-filters/ | |
* | |
* @param array|string $args Optional. Array or string of arguments. See WP_Term_Query::__construct() | |
* for information on accepted arguments. Default empty array. | |
* @return WP_Term[]|int[]|string[]|string|WP_Error Array of terms, a count thereof as a numeric string, | |
* or WP_Error if any of the taxonomies do not exist. | |
* See the function description for more information. | |
*/ | |
function get_terms_all_langs( $args = [] ){ | |
global $sitepress; | |
$has_get_terms_args_filter = remove_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ) ); | |
$has_get_term_filter = remove_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1 ); | |
$has_terms_clauses_filter = remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) ); | |
$terms = get_terms( $args ); | |
if ( $has_terms_clauses_filter ) { | |
add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ), 10, 3 ); | |
} | |
if ( $has_get_term_filter ) { | |
add_filter( 'get_term', array( $sitepress, 'get_term_adjust_id' ), 1, 1 ); | |
} | |
if ( $has_get_terms_args_filter ) { | |
add_filter( 'get_terms_args', array( $sitepress, 'get_terms_args_filter' ), 10, 2 ); | |
} | |
return $terms; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment