• Resolved swaz

    (@swaz)


    I have a wordpress site with two languages: IT and EN.
    On “Settings” -> “Reading” I set “Your homepage displays: Your latest posts”.
    Since I use Polylang for pages only, I would like to show the latest IT articles on the EN homepage, but I can’t find a way to do that.
    I know about the ‘lang’ parameter for a query, but I haven’t found a way to add it to the query used to retrieve the latest posts.
    Thanks for your help.

    • This topic was modified 6 years ago by swaz.
Viewing 1 replies (of 1 total)
  • 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 1 replies (of 1 total)
  • The topic ‘Show the latest posts of a specific language on every homepage’ is closed to new replies.