Forum Replies Created

Viewing 2 replies - 1 through 2 (of 2 total)
  • swaz

    (@swaz)

    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 swaz

    (@swaz)

    I solved it adding this code to functions.php:

    function it_posts_on_homepage( $query ) {
       if ( $query->is_home() && $query->is_main_query() ) {
          $query->set( 'lang', 'it' );
       }
    }
    add_action( 'pre_get_posts', 'it_posts_on_homepage' );

    See also:
    – “How to query content in a different language than the current one?” on this page
    pre_get_posts on WordPress Codex

    • This reply was modified 6 years ago by swaz.
    • This reply was modified 6 years ago by swaz.
Viewing 2 replies - 1 through 2 (of 2 total)