I have a query based on two parameters on a multilingual website (with WPML). To simplify, let's say that one of my filter is the language of the post to retrieve : English, French or all languages. English and French are working fine but I can't make the "all languages" filter work.
Here is my code:
<?php
// First I get the "lang" Get value
$langGet = get_query_var('lang', ICL_LANGUAGE_CODE);
?>
/* 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);
}
// Then I define my query
// Here is the line that is supposed to show all languages but it's not working.
$filters = ( $langGet == 'all' ) ? true : false;
$taxId = apply_filters( 'wpml_object_id', 755, 'project_category' );
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$args = array(
'posts_per_page' => 16,
'post_type' => 'projects',
'tax_query' => array(
array(
'taxonomy' => 'project_category',
'field' => 'term_id',
'terms' => $taxId,
)
),
'orderby' => 'date',
'order' => 'ASC',
'paged' => $paged,
'suppress_filters' => $filters
);
$projects = new WP_Query($args);
But this is not showing all languages. Moreover I noticed that a #038;lang=all
gets added at the end of my url when I am on page 2.
Can someone help me on this? Thanks!