Skip Navigation

[Resolved] Split: Posts created/updated in 2nd language only visible in 2nd language – update post form with wpml with translations

This support ticket is created 4 years, 3 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 24 replies, has 3 voices.

Last updated by simonM-5 4 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#1484597

HI Minesh

Great that you managed to duplicate the site locally. 😉

So, if you're logged in as a Nanny or a Family, you will see a person icon in the menu - there you can either go onto Manage Nanny Ads/Manage Job Ads, depending on what you logged in as. With the mckowski@hotmail.com user for which I provided you access, it has both roles. It's very useful so you don't have to keep switching.

There you can edit individual Ads. It just calls up the relevant Edit Ad Form in a View on a Page.

And yes, all Ad creation and Edits should happen via the frontend.

Please let me know if you need any more assistance.

Kind regards
Simon

#1488755

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I could not reach to this ticket due to the busy queue. I will get in touch with you on Monday.

#1490093
Screenshot 2020-02-03 at 14.29.03.png
Screenshot 2020-02-03 at 14.25.37.png
Screenshot 2020-02-03 at 14.20.11.png

HI Minesh

Looking forward to hearing from you soon with some progress. In the meantime, I have related questions regarding the settings:

1) What setting should we have set on Custom Fields Translation preferences for each custom field under Toolset > Custom Fields > (go into a field group, and open a field) ?

2) Is this overridden by the Translation setting under WPML > Settings > Custom Fields Translation? Or are the two unrelated?

3) Are the settings in 2) overridden completely by WPML > Settings > Post Types Translation?

Thanks and regards
Simon

#1491993

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Regarding your new questions you added with the following post:
=> https://toolset.com/forums/topic/split-posts-created-updated-in-2nd-language-only-visible-in-2nd-language-update-post-form-with-wpml-with-translations/page/2/#post-1490093
- Please open a new tickcet for those questions.

Now, regarding translation of "type of work" taxonomy, there was a silly mistake that I've corrected where I've changed the $post->ID to $post_id that is added to the "edit-native-nanny-ads" code snippet.
I've changed the following line of code from:

 $translated_object_ids[$key] = apply_filters( 'wpml_object_id', $post->ID, $type, false, $key );

To

 $translated_object_ids[$key] = apply_filters( 'wpml_object_id', $post_id, $type, false, $key );

I can see that when you change the Type of work to any other option, its associated translations are automatically set. Please make sure you need to check for Type of Work taxonomy only for now that is the only translation code we added. You need to add such custom code for the other taxonomies you have.

#1498043

HI Minesh

I hope to get back to you this afternoon on this. Sorry for the delayed responses lately.

Best regards
Simon

#1498471

Hi Minesh

I tested with one Nanny Ad - the Type of Work is changing in all languages. This is another step forward. 😀

As I mentioned earlier, I am not a PHP programmer, but I am quite technical in other areas, so if I were to repeat this for all other taxonomies, can I just duplicate lines 25-27 and replace the 'type-of-work' with the other slugs, specifying new variables instead of $trans_types_of_work?

Also would I need to repeat/duplicate lines 31-33 in a similar way?

Thanks and regards
Simon

#1501731

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check now:

I've adjusted the code as given under:

function func_wpml_sync_posts_in_all_languages( $post_id, $form_data ){
$forms = array( 923 );
if ( in_array($form_data['id'],$forms) ){
    global $sitepress;

     $current_language= apply_filters( 'wpml_current_language', NULL );
     $active_langs = $sitepress->get_active_languages();
     unset($active_langs[$current_language]);

     $type = 'native-nanny-ad';
  
  // get/set type-of-work taxonomy
  get_set_translated_items('type-of-work','native-nanny-ad',$post_id,$active_langs);
  
   // get/set available-days taxonomy
  get_set_translated_items('available-days','native-nanny-ad',$post_id,$active_langs);
  
    // get/settime-of-day taxonomy
  get_set_translated_items('time-of-day','native-nanny-ad',$post_id,$active_langs);
   
// add here your remaining taxonomies code as above
  
 
   }
}

add_action( 'cred_save_data', 'func_wpml_sync_posts_in_all_languages', 10, 2 );

function get_set_translated_items($tax_slug,$post_type,$post_id,$active_langs){
    $translated_object_ids = array();
    foreach ( $active_langs as $key=>$val):
        $translated_object_ids[$key] = apply_filters( 'wpml_object_id', $post_id, $post_type, false, $key );        

     foreach($_POST[$tax_slug] as $x=>$y):
        $trans_types_of_work[$key][]  = apply_filters( 'wpml_object_id', $y, $tax_slug, false, $key );
     endforeach;

     endforeach;

     foreach($translated_object_ids as $k=>$id):
        wp_set_object_terms( $id , $trans_types_of_work[$k], $tax_slug);
     endforeach;
}

You should add your new taxonomy as given under:

 // get/settime-of-day taxonomy
  get_set_translated_items('time-of-day','native-nanny-ad',$post_id,$active_langs);
  

Where:
- Replace 'time-of-day' with your taxonomy slug and 'native-nanny-ad' with yoru post type slug.

#1505889

Hi Minesh

Sorry for the delayed response, I'm in Brazil on holiday and internet connection is very weak.

Thanks for the updates to the code. I will try to review this in the coming two days, I need to find a better internet connection to navigate round WordPress Admin comfortably, The connection keep dropping here.

Please be aware there may be longer delays from me whilst on holiday, I will keep trying to check in now and again to review updates.

Thanks and best regards
Simon

#1506421

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

It is ok but what I have help you with is already above and beyond the scope of our support policy. I hope it should work and accordingly you need to adjust the code as per your requirement or even you have a choice to hire pro developer who can help you with your custom requirements.

Thank you for understanding and please feel free to close this ticket 🙂 - enjoy your vacation and free time.

#1525347

Hi Minesh

Thanks for your help with this ticket! I just saw that Toolset Forms has an update.

2.5.5
Improved the compatibility with WPML regarding fields set to copy their values into translations.

Can you give me more detailed information about what changed in the update? This seems to be relevant to my ticket.

Thanks and best regards
Simon

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