Title: Filter Posts by Current Language (WPML)
Last modified: January 24, 2025

---

# Filter Posts by Current Language (WPML)

 *  Resolved [Simone De Gasperin](https://wordpress.org/support/users/simonedegasperin/)
 * (@simonedegasperin)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/)
 * Hi,
 * I’m using the WordPress Popular Posts plugin on a multilingual site with WPML,
   but I’m encountering an issue: the widget shows posts from all languages instead
   of filtering posts by the current language.
 * This is the code I’m using to display the popular posts:
 *     ```wp-block-code
       <?php $args = array(    'wpp_start' => '<ol style="padding: 0;">',    'wpp_end' => '</ol>',    'post_html' => '<li style="list-style: none;" class="list-popolari">                         <div class="flex-display responsive-popolari">                            <div class="col-30 anteprima-articoli1">{thumb}</div>                             <div class="col-70 col-70-popolari">                                <a href="{url}"><h3>{text_title}</h3></a>                                <p class="scrittoda">                                    <i class="far fa-calendar-alt"></i>{date}                                </p>                                <p>{summary}</p>                            </div>                         </div>                    </li>                    <hr class="hr-articoli">',    'thumbnail_width' => 400,    'thumbnail_height' => 300,    'excerpt_length' => 350,    'stats_date' => 1,    'stats_date_format' => 'j F, Y',    'limit' => 3,    'title_length' => 60);if (function_exists('wpp_get_mostpopular')) {    $popolari = wpp_get_mostpopular($args);}?>
       ```
   
 * I’ve tried adding a filter to display posts based on the current language (using
   wpp_query_posts with WPML), but it doesn’t seem to work.
 * Is there an official or recommended way to make the plugin display posts only
   in the current language when using WPML? Could you provide an example implementation
   or guidance on how to configure this correctly?
 * Thanks in advance for your help!
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ffilter-posts-by-current-language-wpml%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

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

 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/#post-18263564)
 * Hi [@simonedegasperin](https://wordpress.org/support/users/simonedegasperin/),
 * From the [Description page](https://wordpress.org/plugins/wordpress-popular-posts/):
 * > **Polylang & WPML 3.2+ support** – Show the translated version of your popular
   > posts!
 * What this means is that WordPress Popular Posts expects all posts to have a translation
   available in the current language. If none are available, it’ll display the post
   in its original language instead. Hence why you’re seeing some posts in their
   original language.
 * In short: there’s no way to “filter” posts by language. Posts need to have a 
   translation available in the current language.
 *  Thread Starter [Simone De Gasperin](https://wordpress.org/support/users/simonedegasperin/)
 * (@simonedegasperin)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/#post-18263579)
 * In the WPML settings, I have configured it so that only translated posts are 
   visible. Using WP_Query and get_posts(), everything works correctly. Can’t I 
   achieve the same result here?
   You can see a screenshot at this link: [https://ibb.co/Vm2Q8GL](https://ibb.co/Vm2Q8GL)
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/#post-18263587)
 * No, unfortunately the plugin currently doesn’t provide such a feature. Might 
   implement it in the future though.
 *  Thread Starter [Simone De Gasperin](https://wordpress.org/support/users/simonedegasperin/)
 * (@simonedegasperin)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/#post-18263589)
 * Ok, thanks for the reply. Could I use get_posts() to retrieve popular posts somehow?
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/#post-18263741)
 * Can’t see how using [get_posts()](https://developer.wordpress.org/reference/functions/get_posts/)
   would solve your problem but to answer your question:
 * **#1** Add [this function](https://gist.github.com/cabrerahector/85320a1ae1e5167766b22df89e4e00d5)
   to your theme’s functions.php file.
 * **#2** Use it with get_posts() like so:
 *     ```wp-block-code
       $popular_post_ids = wp2431_get_popular_posts_ids(['limit' => 3]);if ( $popular_post_ids ) {    $popular_posts = get_posts([        'include' => $popular_post_ids    ]);    // Loop here ...} else {    // No popular posts were found, do something else ...}
       ```
   

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

The topic ‘Filter Posts by Current Language (WPML)’ is closed to new replies.

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

 * 5 replies
 * 2 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [1 year, 4 months ago](https://wordpress.org/support/topic/filter-posts-by-current-language-wpml/#post-18263741)
 * Status: resolved