Skip Navigation

[Resolved] Multi-lingual Post title auto generation with CRED

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.

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

Problem:
How to generate custom taxonomy, dates, and other selectable custom fields title automatically in a different language for each post translation (wpml installed)?

Solution:
For this you can use wpml_current_language hook and put your code for each language. These hook & code needs to be added in the functions.php file:

if($current_language_code == 'en') {
// add your Enlgish code here...
}
 
elseif($current_language_code == 'de') {
// add your German code here...
}

This way code will fetch translated version of the post based on the current language user is viewing the site in.

Relevant Documentation:
https://wpml.org/wpml-hook/wpml_current_language/
https://toolset.com/documentation/translating-sites-built-with-toolset/translating-layouts/

This support ticket is created 7 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 8 replies, has 2 voices.

Last updated by Bruno Simon 7 years, 1 month ago.

Assisted by: Noman.

Author
Posts
#586413

Tell us what you are trying to do?
Titles for my custom posts are automatically generated via code in function.php (see ticket link below); those titles are made out of a string of custom taxonomy, dates, and other selectable custom fields. My question is how to generate those titles automatically in a different language for each post transalation (wpml installed)?

Is there any documentation that you are following?
https://toolset.com/forums/topic/get-custom-taxonomy-in-auto-title/

Is there a similar example that we can see?
Not sure

What is the link to your site?
Locally testing

#586621

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Bruno,

Thank you for contacting Toolset support. For this you can use wpml_current_language hook and put your code for each language:

if($current_language_code == 'en') {
// add your Enlgish code here...
}

elseif($current_language_code == 'de') {
// add your German code here...
}

This way code will fetch translated version of the post based on the current language user is viewing the site in. Thank you

#586626

Hi Noman,
Thanks for your help. Are those hooks to be used withing the function.php file or in the layout?
So far, my titles are generated directly via functions and simply called in the layout via the shortcode [wpv-post-title].
Thanks.

#586638

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

I missed the doc link in my previous reply, so here is doc for the hook wpml_current_language:
https://wpml.org/wpml-hook/wpml_current_language/

- Yes the hook & code needs to be added in the functions.php file.

- And for Translating layouts & its content please take a look at this doc:
https://toolset.com/documentation/translating-sites-built-with-toolset/translating-layouts/

Thank you

#586810

Hi Noman, that part is clearer now; thanks.
I am still struggling with how to effectively generate a post in a particular language: I found this thread on wpml support (https://wpml.org/forums/topic/auto-duplicate-postspages-on-publish/#post-153430) that might help but am still not sure on how to get the translated variables into the title string.
My 'mono' code is

//* CRED autotitle for CREATE custom post
function func_custom_post_title($post_id,$form_data) {
  if ($form_data['id']==XXXX) {
    $term_list = wp_get_post_terms($post_id, 'listing-type', array("fields" => "names","orderby"=>"term_id"));    
    $auctiontype = join("-",$term_list);
    $auctionnumber = get_post_meta($post_id, 'wpcf-auction-number', true);
    $auctiondate = get_post_meta($post_id, 'wpcf-auction-ending', true);
    $auctiondate = date('j F Y',$auctiondate);
    $dayofweek = date('l', strtotime($auctiondate));
    $title= $auctiontype. ': ' .$dayofweek. ' ' .$auctiondate. ': ' .$auctionnumber;}

Thanks.

#586962

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

Please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and check this. Please note that we do not debug custom code or custom requirements much as per our support policy (https://toolset.com/toolset-support-policy/) but I would like to take a look and see what I can find.

Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please also provide link to the page, CRED form backend and share all the needed info.

Thank you

#588942

Hello Noman,
Sorry for the late reaction. I'd like to put this issue on ice right now until my other issues with CRED are fully ironed out.
Cheers.

#589039

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Okay, take your time. I would always be happy to help you.

Have a great day,
Thank you

#591518

Hi Noman,
I will close this ticket for now.
Thanks for your help.

The forum ‘Types Community Support’ is closed to new topics and replies.