• So I have several problems,…

    The JetPack – Infinite Scroll is working nearly perfect. so it’s working on my index.php where I call posts.

    1.
    It does not work on my custom post types, is it even possible?

    2.
    Also I am using the plugin Polylang, so if I change for example to spanish – it does not load anything sadly, but works with default language english.

    Okay I found out that the mixxing of the languages.. kills the infinite scroll when using polylang.

    add_filter('pre_get_posts', 'get_default_language_posts');
    
    function get_default_language_posts($query) {
        if ($query->is_main_query() && function_exists('pll_default_language') && !is_admin()) {
            $terms = get_terms('post_translations'); //polylang stores translated post IDs in a serialized array in the description field of this custom taxonomy
            $defLang = pll_default_language(); //default lanuage of the blog
            $curLang = pll_current_language(); //current selected language requested on the broswer
            $filterPostIDs = array();
            foreach ($terms as $translation) {
                $transPost = unserialize($translation->description);
                //if the current language is not the default, lets pick up the default language post
                if ($defLang != $curLang)
                    $filterPostIDs[] = $transPost[$defLang];
            }
            if ($defLang != $curLang) {
                $query->set('lang', $defLang . ',' . $curLang);  //select both default and current language post
                $query->set('post__not_in', $filterPostIDs); // remove the duplicate post in the default language
            }
        }
        return $query;
    }
  • The topic ‘Jetpack – Infinite Scroll – Custom Post Types – Polylang’ is closed to new replies.