所以我成功了。问题不在于过滤器,而在于税务查询。以下是可能感兴趣的人的解决方案。
<?php
// I check the lang query var if it\'s empty we\'ll display all languages
$langGet = get_query_var(\'lang\', \'all\');
?>
/* Then have my form to filter posts */
<form action="<?php echo get_permalink( get_the_ID() ); ?>" method="get">
<label for="lang"><?php _e( \'Languages\', \'mytextdomain\' ); ?></label>
<?php
$languages = apply_filters( \'wpml_active_languages\', NULL );
if($languages) { ?>
<select name="lang">
<?php foreach($languages as $language) : ?>
<option value="<?php echo $language[\'language_code\']; ?>" <?php echo ( $langGet == $language[\'language_code\'] ) ? \'selected\' : \'\'; ?>><?php echo $language[\'translated_name\']; ?></option>
<?php endforeach; ?>
<option value="all" <?php echo ( $langGet == \'all\' ) ? \'selected\' : \'\'; ?>><?php _e(\'All languages\', \'mytextdomain\'); ?></option>
</select>
<?php } ?>
<input type="submit" value="<?php _e( \'Filter projects\', \'mytextdomain\' ); ?>">
</form>
<?php
// Then I set up the switch for current language
if( $langGet != \'all\' ) {
global $sitepress;
$current_lang = $sitepress->get_current_language();
$sitepress->switch_lang($langGet, true);
$taxTerms = array( apply_filters( \'wpml_object_id\', 755, \'project_category\' ) );
$filters = false;
} else {
// If we want to display all languages we have to remove filters
global $sitepress;
remove_filter( \'get_terms_args\', array( $sitepress, \'get_terms_args_filter\' ), 10 );
remove_filter( \'get_term\', array( $sitepress, \'get_term_adjust_id\' ), 1 );
remove_filter( \'terms_clauses\', array( $sitepress, \'terms_clauses\' ), 10 );
$taxTerms = array( 755, 776, 777, 778 );
$filters = true;
}
$paged = (get_query_var(\'paged\')) ? absint(get_query_var(\'paged\')) : 1;
// Then we set the query
$args = array(
\'posts_per_page\' => $postsperpage,
\'post_type\' => \'projects\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'project_category\',
\'field\' => \'term_id\',
\'terms\' => $taxTerms
)
),
\'orderby\' => $orderby,
\'order\' => $order,
\'meta_key\' => $metakey,
\'paged\' => $paged,
\'suppress_filters\' => $filters
);
$projects = new WP_Query($args);