WPML: tax_query returns empty results in non-default languages

Stumbled upon this ridiculous issue.

Consider the following simplified code:

$args = array(
 'post_type' => 'project',
);

$args['tax_query'] = array(array(
 'taxonomy' => $_GET['tax'],
 'field' => 'id',
 'terms' => $_GET['term_id']
));

$custom_wp_query = new \WP_Query($args);

var_dump($custom_wp_query->get_posts());

With WPML, this code works and returns the posts from the specified taxonomy and term. But only if it’s the default language. Other languages return nothing.

Fix?

$args['tax_query'] = array(array(
 'taxonomy' => $_GET['tax'],
 'field' => 'id',
 'terms' => array($_GET['term_id'])   // this must be an array..
));

..even though Codex says ‘terms’ can be int, string or array 🙁

Indrek Kõnnussaar

I'm a veteran Wordpress developer, context-driven tester, security enthusiast and the mastermind behind Codelight. I love building stuff that works and fixing stuff that doesn't.

Write me directly indrek@codelight.eu
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×