WPML: how to show places in default language when translation is missing

This topic contains 17 replies, has 3 voices, and was last updated by  Stiofan O’Connor 9 years, 6 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket

Tagged: 

  • Author
    Posts
  • #16022

    wu
    Free User
    Post count: 41

    The title gives it pretty much away. How can that be achieved for listings and detail pages?
    So if there is for example mostly content in the default language, the home page and other listings should display the posts in the default language for those posts that are not translated.

    I don’t know if it is related, but after I installed WPML, the virtual pages did not show up anymore in the pages section. I opened the pages directly via entering their id that I found out in the database, set the language to my default language and resaved them. Then I added translations to them. After that, they show up again in the pages section.

    #16027

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi wu,

    I am sure there is a setting in wpml somewhere for that, have you found this and it’s not working or have you just not found this setting?

    Stiofan

    #16031

    wu
    Free User
    Post count: 41

    All that I found is the switch that decides if places get translated or not.
    In both options, the listings only display places with the current languages.

    #16033

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    as far as i know the setting is here:
    WPML>Languages>Language switcher options>How to handle languages without translation>>

    Stiofan

    #16034

    wu
    Free User
    Post count: 41

    I tried both settings, but got the same result: it only shows places in the current language and nothing if there is no translation for the current language.

    #16039

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi wu, i tried and got the same result, i don’t use WPML much and i’m not sure if this is the designed functionality, can you maybe ask on the wpml forum?

    Stiofan

    #16143

    wu
    Free User
    Post count: 41

    What I found out so far, is that there is a setting called “Blog posts to display” that does exactly what I need, but only for blog posts and not for other post types. As I understand, it would require custom coding for other post types.

    Here I found an example for that:

    http://wpml.org/forums/topic/custom-post-type-content-from-default-language-to-display-in-2nd-language/

    
    
    
    /* WPML
     * Display default content on missing languages
     */
    add_filter('icl_ls_languages', 'wpml_ls_filter');
     
    function wpml_ls_filter($languages) {
        global $sitepress;
     
        $default_url = $languages[$sitepress->get_default_language()]['url'];
        foreach($languages as $lang_code => $language){
            if($languages[$lang_code]['missing']==1){
                $languages[$lang_code]['url'] = $default_url;
            }
        }
    return $languages;
    } 
    

    But in that form it does not work.
    Maybe I need to attach it to another hook?

    Or would some customization of the query like in that thread be needed?

    #16148

    Paolo
    Site Admin
    Post count: 31206

    Hi,

    this looks like a good question for WPML forum?

    Thanks.

    #16376

    wu
    Free User
    Post count: 41

    The guys over there are asking for the code that displays the posts.
    I think it is code in geodirectory-functions/listing_filters.php, but I am not sure about that. Could you please point me to the correct location?

    #16384

    wu
    Free User
    Post count: 41

    When I replace:

    
    
    
    $where .= " AND icl_t.language_code = '$lang_code' AND icl_t.element_type IN('post_".$q_post_type."') ";
    

    with:

    
    
    
    $where .= " AND icl_t.language_code = '$default_lang_code' AND icl_t.element_type IN('post_".$q_post_type."') ";
    

    in geodir_default_where(), posts are showing up only in the default language only, so this seems to be the right place.

    Is this function controlling all GeoDirectory posts on all pages, or is there more code to look out for?

    #16398

    Paolo
    Site Admin
    Post count: 31206

    That is correct for listings pages. For widgets like popular post view these are in geodirectory/geodirectory-widgets.

    Thx

    #16833

    wu
    Free User
    Post count: 41

    The support over there is telling me to add an “OR” statement to the “WHERE” part to include the default language or the translations.
    I tested this and found out that the place is showing up twice if there is a translation.
    The support now suggests to filter that out in a while loop.
    What is your opinion about this?
    I am almost sure this will collide with pagination, “num_rows” and “LIMIT” in the query, as the query will return the wrong number of rows in some cases.
    What can I tell them?

    #16849

    Stiofan O’Connor
    Site Admin
    Post count: 22956
    This reply has been marked as private.
    #16858

    wu
    Free User
    Post count: 41
    This reply has been marked as private.
    #16976

    wu
    Free User
    Post count: 41
    This reply has been marked as private.
Viewing 15 posts - 1 through 15 (of 18 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket