REST API

The feature is available only in Polylang Pro.

The ‘lang’ argument

It is possible to get posts or terms in only one language. For example:

GET /wp/v2/posts?lang=fr

lists all posts in French, while

GET /wp/v2/posts

lists all posts in all languages.
The ‘lang’ argument works for requests related to the posts and terms, whatever the post type or taxonomy.

The language and translations in responses

When querying posts or terms, two new fields are added to the response.

  • ‘lang’: contains the language code (generally 2 letter ISO code) of the queried post or term.
  • ‘translations’: contains an array with the language codes as keys and the id of the translated posts or terms as values. The array always includes the queried post or term itself.

Assign the language and translations

It is not only possible to get the language and translations of posts and terms but it is also possible to assign them. For example:

POST /wp/v2/posts/3376?lang=fr&translations[en]=3374

will assign the French language to the post 3376 and link it to the post 3374 as its English translation. Note that you must first make sure that the post 3374 is in English.

Get the languages

Apart from extending the WP API, it is possible to get the languages with an additional endpoint:

GET /pll/v1/languages

The response will include several properties such as:

  • name: native language name
  • slug: language code (generally 2 letter ISO code)
  • locale: WordPress locale
  • flag_url: the url of the flag associated to the language
  • home_url: the url of the home page in that language
  • page_on_front: if relevant, the id of the static front page in that language
  • page_for_posts: if relevant, the id of the page for posts in that language

The list above is not exhaustive as the response includes several other internal properties.