Title: WordPress popular posts and WPML
Last modified: August 22, 2016

---

# WordPress popular posts and WPML

 *  Resolved [khuongcomputer](https://wordpress.org/support/users/khuongcomputer/)
 * (@khuongcomputer)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/)
 * As wpp does not support WPML, I did a little modification so it would show the
   correct posts in the respective languages.
 * File wordpress-popular-posts.php, line 1418, above // * posts exclusion add
 * `if(defined("ICL_LANGUAGE_CODE")) $where .= " AND p.ID IN ( SELECT element_id
   as ID FROM {$wpdb->prefix}icl_translations WHERE language_code='".ICL_LANGUAGE_CODE."')";`
 * Now wpp should display the post in the current language. Just hope that the author
   will fix and add WPML support for the plugin soon.
 * [https://wordpress.org/plugins/wordpress-popular-posts/](https://wordpress.org/plugins/wordpress-popular-posts/)

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

 *  Thread Starter [khuongcomputer](https://wordpress.org/support/users/khuongcomputer/)
 * (@khuongcomputer)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455109)
 * Sorry my bad, after an update I found out that the plugins has already support
   WPML, but there’re small bug which will show posts from other languages if there’re
   no respective post in the current languages.
 * Line ~1738
    `$current_id = icl_object_id( $p->id, get_post_type( $p->id ), true,
   ICL_LANGUAGE_CODE );` change true to false
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455151)
 * Hi there,
 * That’s not a bug. Actually, it’s intended to be that way. If a post / page has
   been translated into the current language or not falls outside the scope of WPP.
 * Also, setting the third parameter –_return\_original\_if\_missing_– to false 
   will have icl_object_id() return `NULL` (see [WPML’s icl_object_id() documentation](http://wpml.org/documentation/support/creating-multilingual-wordpress-themes/language-dependent-ids/)
   for more). This will make WPP add a LI element without a post title in the case
   the current post in the iteration has no translation available – which is not
   what I’d like to happen.
 *  [anou](https://wordpress.org/support/users/anou/)
 * (@anou)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455153)
 * Hello,
 * There is also one “error” for WPML support line 1289, in the `__update_views()`
   function:
    If no posts was created in the original/default language, the var `
   $id = 0` so the function inserts 0 for postid in the WPP tables.
 * I think the line should be:
    `$id = icl_object_id( $id, get_post_type( $id ),
   true, $sitepress->get_default_language() );` I’ve changed “false” by “true” so
   the post ID in the language of creation is inserted instead of “0”.
 * The other “problem” I’ve detected, but it’s maybe only related to my website,
   is that the code suggested by kuongcomputer above for the `__render_popular_post()`
   function doesn’t work for me, because ICL_LANGUAGE_CODE constant is always returning
   the default language…
 * After searching in vain, I think it’s maybe a problem of plugins loading order
   or ajax function call… I’m stuck now. If you have any idea why this constant 
   is not set has it should (it’s ok on front but not in the WPP function), I’m 
   listening!
 * The consequence of this is that the widget displays posts in the default language
   even if current language is not the default one.
 * And thanks for your time and module
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455156)
 * > There is also one “error” for WPML support line 1289, in the __update_views()
   > function:
   >  If no posts was created in the original/default language, the var
   > $id = 0 so the function inserts 0 for postid in the WPP tables.
   > I think the line should be:
   >  `$id = icl_object_id( $id, get_post_type( $id ),
   > true, $sitepress->get_default_language() );` I’ve changed “false” by “true”
   > so the post ID in the language of creation is inserted instead of “0”.
 * You’re right, somehow I overlooked that. Thanks for the notice, [it’ll be fixed soon](https://github.com/cabrerahector/wordpress-popular-posts/issues/50).
 * > The other “problem” I’ve detected, but it’s maybe only related to my website,
   > is that the code suggested by kuongcomputer above for the __render_popular_post()
   > function doesn’t work for me, because ICL_LANGUAGE_CODE constant is always 
   > returning the default language…
   > …
   > The consequence of this is that the widget displays posts in the default language
   > even if current language is not the default one.
 * I’ll take a look into this and reply back as soon as I can.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455247)
 * Hi **[@anou](https://wordpress.org/support/users/anou/)**!
 * Just checked your report about the `ICL_LANGUAGE_CODE` constant always returning
   the default language, and I’m unable to replicate the problem here (see [screen capture](http://i62.tinypic.com/akwz5u.jpg)).
   Posts and pages are being translated correctly as well, even with the _Ajaxify
   widget_ feature enabled.
 *  [anou](https://wordpress.org/support/users/anou/)
 * (@anou)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455275)
 * Hello,
    thanks for your answers, but I finally found that I must disabled the“
   Ajaxify widget:” option in order to have the right `ICL_LANGUAGE_CODE` constant.
   If enabled, the constant always returns the default language.
 * So maybe the only difference between us, is that your are testing on localhost
   and me on a live website…
 * I will keep digging…
 * Thanks again.
 *  Plugin Author [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * (@hcabrera)
 * [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455276)
 * > So maybe the only difference between us, is that your are testing on localhost
   > and me on a live website…
 * That shouldn’t make any difference, since the plugin uses the exact same function
   top build the popular list (and actually the AJAX version runs after everything’s
   loaded, so it should pick up the current language just fine).
 * Could maybe a third party plugin be causing a conflict with WPML? Have you tried
   disabling all of your plugins (except WPP) already?

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

The topic ‘WordPress popular posts and 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/)

 * 7 replies
 * 3 participants
 * Last reply from: [Hector Cabrera](https://wordpress.org/support/users/hcabrera/)
 * Last activity: [11 years, 7 months ago](https://wordpress.org/support/topic/wordpress-popular-posts-and-wpml/#post-5455276)
 * Status: resolved