Title: Programmatically set language?
Last modified: August 21, 2016

---

# Programmatically set language?

 *  [david.tonarini](https://wordpress.org/support/users/davidtonarini/)
 * (@davidtonarini)
 * [11 years, 9 months ago](https://wordpress.org/support/topic/programmatically-set-language/)
 * Hi,
    I´ve recently activated Polylang in my wordpress installation. All is working
   fine, however since I am integrating two different systems in my website, in 
   some occasions I need to have the language set from an external variable.
 * How can I achieve that?
    I need this mostly when loading the widgets, because
   I need to show the list of recent post and so on accordingly to my external variable.
 * I have been looking throught the Polylang code, but I´m not yet sure on how properly
   do that.
 * Thank you, kind regards.
 * [https://wordpress.org/plugins/polylang/](https://wordpress.org/plugins/polylang/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [dina_fire](https://wordpress.org/support/users/dina_fire/)
 * (@dina_fire)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/programmatically-set-language/#post-5158154)
 * After poking around in the database of my site, I figured out how Polylang stores
   its language information – as taxonomy terms, in the wp_terms table. It’s not
   a perfect solution for a number of reasons, but you could just check what the
   ID of your desired language is and use wp_set_object_terms() to add the term 
   to your posts.
 * Ideally you (and I) would use a function native to Polylang to avoid hunting 
   in the database for the term ID, not to mention to avoid having to implement 
   the fix differently on different websites, but I unfortunately don’t know of 
   such a function.
 * Hope this helps, as far as it can.
 *  Plugin Author [Chouby](https://wordpress.org/support/users/chouby/)
 * (@chouby)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/programmatically-set-language/#post-5158155)
 * Hi!
 * Is this what you are looking for? [https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/#pll_set_post_language](https://polylang.wordpress.com/documentation/documentation-for-developers/functions-reference/#pll_set_post_language)
 *  [dina_fire](https://wordpress.org/support/users/dina_fire/)
 * (@dina_fire)
 * [11 years, 2 months ago](https://wordpress.org/support/topic/programmatically-set-language/#post-5158156)
 * Perfect, thank you.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Programmatically set language?’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

## Tags

 * [programmatically](https://wordpress.org/support/topic-tag/programmatically/)

 * 3 replies
 * 3 participants
 * Last reply from: [dina_fire](https://wordpress.org/support/users/dina_fire/)
 * Last activity: [11 years, 2 months ago](https://wordpress.org/support/topic/programmatically-set-language/#post-5158156)
 * Status: not resolved