Polylang
Integration with the Polylang plugin, adding fields and filters to select the language when fetching data on a multilingual site.


Click to watch tutorial video - 02:56
Integration with the Polylang plugin (and also Polylang PRO).
When Polylang is installed in the WordPress site, fetching data using GraphQL would retrieve results for all languages. For instance, field posts
might fetch posts in English, Spanish and French.
With the Polylang integration, fields get an extra argument polylangLanguagesBy
, to fetch data for some specific language only:
{
posts(
filter: {
polylangLanguagesBy: {
codes: ["en"]
}
}
) {
title
polylangLanguage {
code
}
}
pages(
filter: {
polylangLanguagesBy: {
locales: ["en_US"]
}
}
) {
title
polylangLanguage {
locale
}
}
customPosts(
filter: {
polylangLanguagesBy: {
predefined: DEFAULT
}
customPostTypes: "some-cpt"
}
) {
title
polylangLanguage {
code
}
}
}