Skip Navigation

[Resolved] Print all posts in a view regardless the language

This thread is resolved. Here is a description of the problem and solution.

Problem:

I want view to print all user's posts regardless the page language.

Solution:

This is expected result, Views will output posts of specific language by current page.

You might consider to use display a language switcher, after user click the language links, Views will output posts of specific language. for example:

https://toolset.com/forums/topic/print-all-posts-in-a-view-regardless-the-language/#post-1244396

Relevant Documentation:

This support ticket is created 5 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by AndreasP4791 5 years, 8 months ago.

Assisted by: Luo Yang.

Author
Posts
#1243254

Hello,

I have a view showing user's posts. This view filters the results based on the post language.

When view 'opens' in an English page, then only English posts are shown while view 'opens' in a Greek page only Greek posts are shown?

How will I override this? I want view to print all user's posts regardless the page language.

Thank you!

#1243396

Hello,

I assume you are using WPML plugin to translate the posts.

If it is, this is expected result, Views will output posts of specific language by current page.

You might consider to use display a language switcher, after user click the language links, Views will output posts of specific language.

#1243479

Yes, I use WPML.. Are you sure that this is the default behaviour? It sounds very strange..!

#1243488

Yes, I am sure that it is default behavior, using WPML plugin, in Greek page, Views will output only posts in Greek language.

#1244134

Could I have a page which is untranslated in order to have posts of all languages? Is this possible?

It sounds very strange to me not to have posts of all languages in a toolset view.

Thank you!

#1244396

For the question:
Could I have a page which is untranslated in order to have posts of all languages?

As I mentioned above, there isn't such kind of feature within Views plugin, if you agree, I can escalate this issue as a feature request.

Currently, I suggest you display link of post translations, for example:
1) Create a custom shortcode, put below PHP codes into your theme file functions.php:

function wpml_post_languages_in_loop() {
    $post_trid = apply_filters('wpml_element_trid', NULL, get_the_ID(), 'post_' . get_post_type());
     
    if (empty($post_trid)){
        return;
    }
     
    $active_langs = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0' );
    $translations = apply_filters('wpml_get_element_translations', NULL, $post_trid, 'post_' . get_post_type());
    if (is_array($translations) && !empty($translations)) {
         
        $langs = array();
        foreach ($translations as $translation) {
            if (is_object($translation) && isset($active_langs[$translation->language_code]) && $translation->element_id != get_the_ID()) {
                $langs[] = '<a href="' . apply_filters('wpml_permalink', ( get_permalink($translation->element_id)), $translation->language_code) . '"><img src="' . ICL_PLUGIN_URL . '/res/flags/' . $translation->language_code . '.png" width="18px" height="12px"></a>';
            }
        }
         
        if (!empty($langs)) {
            return __('This post is also available in', 'wpml') . ': ' . implode('  ', $langs);
        }
    }
}

add_shortcode('post_translation_links', 'wpml_post_languages_in_loop');

2) Edit your post view, in section "Loop Editor", within View's loop, display above shortcode, like this: [post_translation_links]

#1244412

Thank you Luo!

Yes, please escalate this issue as a feature request.