• Resolved Christoph

    (@camthor)


    Hi,

    I’m trying to make my code compatible with Polylang. So far it only works with WPML, so I try to figure out the equivalent for your plugin.

    I need to switch the language before retrieving posts with WP_Query so that I can parse the posts for all available languages. With WPML I would call before retrieving the posts:

    $sitepress->switch_lang( $language_code );

    What would be the equivalent for Polylang?

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • You have to add the ‘lang’ parameter to your query.
    Then you can set it to an empty string in order to query posts from all languages, or to one or more language codes.

    Examples:

    // All languages
    $the_query = new WP_Query( array( [...], 'lang' => '') );
    // English only
    $the_query = new WP_Query( array( [...], 'lang' => 'en') );
    // English and French only
    $the_query = new WP_Query( array( [...], 'lang' => 'en,fr') );

    See this page

    Thread Starter Christoph

    (@camthor)

    Thank you!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Need to switch language before WP_Query’ is closed to new replies.