How to get posts in different language from WPML Plugin

i’m using Thermal-Api plugin in order to define a REST WS to get posts in JSON format.

My Client uses WPML to translate posts and i need to pass to WP_Query the language set in front-end side.

Read More

Is there a particular parameter to pass to WP_Query to select only the post in that language or is there a way to change dynamically “ICL_LANGUAGE_CODE” in order to retrieve what i need??

Thanks!!

Related posts

1 comment

  1. Assuming $new_lang holds the desired two letter language code (e.g. ‘fr’), you can do this:

    global $sitepress;
    $current_lang = $sitepress->get_current_language(); //save current language
    $sitepress->switch_lang($new_lang);
    //...run query here; if you use WP_Query or get_posts make sure you set suppress_filters=0 ... 
    $sitepress->switch_lang($current_lang); //restore previous language
    

    For more info, check http://wpml.org/documentation/support/achieving-wpml-compatibility-for-your-themes-and-plugins/debugging-theme-compatibility/

Comments are closed.