• Resolved netzstrategen

    (@netzstrategen)


    Hey, I hope you’re doing well.
    We have a problem with the display of posts in relation with WPML.
    Posts that are not in the default language are only displayed if they are a translation of a post in the default language. If they are independent pages in a foreign language, i.e. not translations, they are not displayed in the back end.
    Our developer asks for the following adjustment:
    Would this be possible?

    The way the nested pages plugin works is that it includes a post into the count if it is a translation of another post in the default language ‘de’. The translatedPostCount() function makes a query that gets the posts that have source_language_code = ‘de’:
    SELECT COUNT( wp_posts.ID ) FROM wp_posts LEFT JOIN wp_icl_translations ON wp_posts.ID = wp_icl_translations.element_id WHERE wp_icl_translations.language_code = 'en' AND wp_icl_translations.source_language_code = 'de' AND wp_icl_translations.element_type = 'post_reference-highlight'
    The source_language_code is set to ‘de’ only for posts that are a translation of the default post in de, otherwise it is set to NULL.

    Queries that need to be modified:
    in translatedPostCount():

    $wpdb->prepare("SELECT COUNT( {$wpdb->prefix}posts.ID ) FROM {$wpdb->prefix}posts LEFT JOIN {$wpdb->prefix}icl_translations ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}icl_translations.element_id WHERE {$wpdb->prefix}icl_translations.language_code = '%s' AND {$wpdb->prefix}icl_translations.source_language_code = '%s' AND {$wpdb->prefix}icl_translations.element_type = '%s'", $language_code, $default_language_code, $post_type"
    ->
    $wpdb->prepare("SELECT COUNT( {$wpdb->prefix}posts.ID ) FROM {$wpdb->prefix}posts LEFT JOIN {$wpdb->prefix}icl_translations ON {$wpdb->prefix}posts.ID = {$wpdb->prefix}icl_translations.element_id AND {$wpdb->prefix}icl_translations.element_type = CONCAT('post_', {$wpdb->prefix}posts.post_type) WHERE {$wpdb->prefix}icl_translations.language_code = '%s' AND {$wpdb->prefix}icl_translations.element_type = '%s'", $language_code, $post_type")

    in defaultPostCount():

    $wpdb->prepare("SELECT COUNT(p.ID) FROM {$wpdb->prefix}posts AS p LEFT JOIN {$wpdb->prefix}icl_translations AS t ON t.element_id = p.ID WHERE p.post_type = '%s' AND p.post_status = 'publish' AND t.language_code = '%s'", $post_type, $default_language_code)
    ->
    $wpdb->prepare("SELECT COUNT(DISTINCT p.ID) FROM {$wpdb->prefix}posts AS p LEFT JOIN {$wpdb->prefix}icl_translations AS t ON t.element_id = p.ID AND t.element_type = CONCAT('post_', p.post_type) WHERE p.post_type = '%s' AND t.language_code = '%s'", $post_type, $default_language_code)

    Best regards
    Henning

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Nested Pages / WPML – Not showing all translations’ is closed to new replies.