Skip Navigation

[Resolved] Conditional output: language using polylang

This support ticket is created 4 years, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

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 13 replies, has 2 voices.

Last updated by Tcoffee 4 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1346837

Tell us what you are trying to do? I'm trying to create an Arabic version of my website where im using the polylang plugin for the same. In one view I need to show read more button in both languages. How can I achieve it in the same view using conditional output?

Is there any documentation that you are following? https://toolset.com/forums/topic/conditional-output-language/

Is there a similar example that we can see?

What is the link to your site? hidden link (events section in home page)

Thanks in advance.

#1346891

Hello,

The thread you mentioned above is for WPML plugins:
https://wpml.org/

Since you are using polylang plugin, you will need to consider other custom shortcode, for example:
hidden link

For your reference.

#1347145
view.png
setting.png
functions.png

Hi,

I have tried the above shortcode but it is not working. adding screenshots for your reference.

Can you please help me on this.

#1347721

Since it is a custom codes problem, please provide a test site with the same problem, fill below private message box with login details and FTP access, also point out these:
- The problem page URL
- Where I can edit your PHP codes.

I need a live website to test and debug, thanks

#1347877

Thanks for the details, I can log into your website, will update here if there is anything found

#1347913

I have done below modifications in your website:
1) Dashboard-> Toolset-> Settings-> Front-end Content
in section "Functions inside conditional evaluations", add function name: get_locale
More help:
https://developer.wordpress.org/reference/functions/get_locale/

2) Edit the post view "Latest Event":
hidden link
in section "Loop Editor", change the codes as below:

[wpv-conditional if="( get_locale() eq 'en_US' )"]<a href="[wpv-post-url]">Read More</a>[/wpv-conditional] 
[wpv-conditional if="( get_locale() eq 'ar' )"]<a href="[wpv-post-url]">إقرأ المزيد</a>[/wpv-conditional]

Please test again, check if it is what you want, thanks

#1347931

Hi,

This is what I'm seeing. Arabic Version: hidden link , English version: hidden link

The issue is still not resolved. can you please take a look.

#1347967
Arabic.JPG

I assume we are talking about Arabic Version URL:
hidden link

I see different result from your screenshot, I can see the text in Arabic "إقرأ المزيد", here is the my screenshot: Arabic.JPG

Can you try to clear your browser cache and test again?

#1348043

Hi,

I don't think it is cache. can you please check again. I have tried in different systems and browsers getting the same result.

Results in edge browser: EN: hidden link, AR: hidden link

Please cross check.

#1348583

Thanks for the details, I am checking it in your website, will update here if there is anything found.

#1348645

Here are what I found:
1) In your screenshot EN:
hidden link

It is a page in English, and showing a Arabic post, so the function get_locale() shows text in Arabic.

2) Same as above, in the another screenshot AR:
hidden link

It is a page in Arabic, and showing a English post, so the function get_locale() shows text in English.

Are you going to do these:
In English post, show the text in English in Arabic post? Can you confirm it first??

#1348667

Hi,

This is actually an issue occurs when we use the conditional statement with the third party shortcode inside the view.

If we remove the conditional statement, it will show English content in the English version and Arabic content in the Arabic version. (Except Read More text) .

We want to show English content in English version and Arabic content in Arabic version including Read More button.

Hope this helps.

#1348775

To avoid any more misunderstand, let me describe the question with more details:
In your screenshot EN:
hidden link

It is a page in English(hidden link), you are using post view "Latest Event", and it showing a Event post in Arabic.

Are you going to display English posts only(without any Arabic post) in that page? Can you confirm it first?

If it is, then wpv-conditional shortcode won't work in this case, since it can only check language current post(Arabic post), you will need to consider other custom codes, for example, I have done below modifications in your website:
1) Dashboard-> Toolset-> Settings-> Custom codes
hidden link

Add a Custom code snippet "polyang_filter", with below PHP codes:

add_filter('wpv_filter_query', function($args, $settings, $view_id){
    if($view_id == 390){ // Latest Event view's ID
      $lang = get_locale();
      if($lang == "en_US"){
        $lang = 'en';
      }
      $args['lang'] = $lang;
    }
    return $args;
}, 999, 3);

It will apply polyang language into view's filter

2) Edit the page "Home",
hidden link
find the Latest Event view's shortcode, replace it from:
{!{wpv-view name='latest-event'}!}

To:
{!{wpv-view name='latest-event' cached="off"}!}

It will turn off view's cache

Please test again, check if it is what you want.

More help:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query

#1349751

My issue is resolved now. Thank you for your support. Hope this ticket helps others also.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.