• My setup is an English and Greek bilingual installation. However since my visitors understand both languages, their browser defaults may prefer either. But they may never visit the second language, therefore certain untranslated posts won’t be visible to them.

    I want to show posts from all languages in the archives, unless they have a proper translation of course. To keep content semantically and visually separated, I am using the lang attribute and CSS3 to style posts differently.

    I have managed to work around it using code from an older post, but cannot get it to work with the default language.

    I’m afraid my obstacle is inherent to how Polylang works. Is there any chance that we can see this functionality in the plugin Settings? Any way to modify my code to make it work?

    add_filter( 'pre_get_posts', 'get_default_language_posts' );
    function get_default_language_posts( $query ) {
    	if ( $query->is_main_query() && is_home() && function_exists('pll_languages_list') && !is_admin()){
    		$languages = pll_languages_list( array( 'hide_empty' => 1 ) );
    		$terms = get_terms('post_translations');
    		$lang_default =  pll_default_language();
    		$lang_current =  pll_current_language();
    		$post_ids = array();
    
    		foreach($terms as $translation){
    			$transPost = unserialize($translation->description);
    			if($transPost[$lang_current] != 0) { //has no translation in $lang_current
    				$post_ids[]=$transPost[$lang_default];
    			}
    		}
    
    		if($lang_default!=$lang_current){ //without this check, default language returns zero posts
    			$query->set('lang' , join( ',', $languages ) );
    			$query->set('post__not_in', $post_ids);
    		}
    	}
    
    	return $query;
    }
Viewing 2 replies - 16 through 17 (of 17 total)
  • adding an “ALL LANGUAGES” option in the page/post language selection drop down list in the dashboard.

    If you mean the language selector in the post edit screen, then this would remove the language tag from the post and probably the site’s main language tag would be (incorrectly) applied. This is not a good idea, because every post needs a correct language tag/attribute (except the post itself is a language mix).

    The implementation must be one level higher, when it comes to decide which languages are displayed in a given situation.

    Probably the ‘easiest’ thing would be a per-post meta tag that tells Polylang for which languages —in addition to the posts own language— the post should be displayed. For example, a possible meta tag for an English post: '+fr, +de'

    Yes I guess that would do the trick.
    If these meta tags are added to the post, then the post will show up in the website when any of these languages is selected, and without the website switching back to the default language (e.g. FR menus still displayed even tough the post is in English).

    Again, the WPML docs mention a “translatable” attribute that lets you specify that a post will not be translated, resulting in the post showing up in the website no matter which language is selected. Haven’t tried it though…

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Show posts from other languages’ is closed to new replies.