Does Polylang auto-filter for posts language on language page?


SO, the following happened, and I just want to make sure that this is normal functioning, and I don’t need to code a backup plan if this fails.

  • Say you have a page A, whose language is set via Polylang Plugin to english.
  • You have a post of a custom type called my_own_post, translated in eight languages; one of them being english.
  • You then have a custom post taxonomy, called my_tax.
  • You don’t apply polylang to my_tax; meaning that a term of it, for example my_term, has the same name my_term_name across all eight languages, but different slugs (I’m using the standard version of polylang, not the pro where slugs can be shared across languages).

NOW, on page A, I query posts via the loop which have:

  • a post type my_own_post
  • a my_tax term name equal to my_term_name

with this:

$args = array(
    'post_type' => 'my_own_post',
    'tax_query' => array(
            'taxonomy' => 'my_tax',
            'field'    => 'terms',
            'terms'    => 'my_term_name',
$query = new WP_Query( $args );

Although I didn’t specify any language parameter anywhere in this query, WP perfectly returns the posts which have the taxonomy term named 'my_term_name' bound to them, in english only. I assume this is due to the initial filtering of polylang because the page A is in english. Is that so, and does this way of filtering always work?

In other words, if I query for posts of a specific language, and the page on which I query for them is already in a specific language, AND my taxonomies are not saved per language, but with the same name across all languages: In this case, to get what I want; I actually don’t even need to filter in function of the language in the post query in any way, correct?

DevelJoe 2 years 2020-12-20T08:10:43-05:00 0 Answers 8 views 0

Leave an answer