Passing an identifier to the translated message in save_post

I have a method associated with the save_post action, WPML is used as a translation plugin, I am trying to find a way that, after adding a translation, and the published one is clicked, and the save_post method is launched to find out the identifier of the original message.

So far, I have found that this can only be done when the message has already been published and an update has been initiated. To do this, the icl_object_id method ($ translation_post_id, 'post', false, 'en' → English is the language in which the original post will always be created);

See the MSG comment to see above in context.

function my_project_updated_send_email( $post_id, $post, $update ){ if ( 'publish' == get_post_status( $post_id ) && 'events' == get_post_type($post)) { if(ICL_LANGUAGE_CODE == 'en'){ // Shortened - Everything works fine }elseif (ICL_LANGUAGE_CODE == 'it'){ //Get English Language Post ID $id = icl_object_id($post_id,'post',false,'en'); //MSG: $id returns empty on publish, but returns fine on update $event_id = get_field('event_id', $id); if($event_id == ""){ // Shortened - Everything works fine } } } } add_action( 'save_post', 'my_project_updated_send_email', 10, 3); 
+5
source share
1 answer

The problem is with your hook, that is, "save_post"

" save_post " does not work when you post a post. You can use publish_post for this.

https://codex.wordpress.org/Plugin_API/Action_Reference/publish_post

You can also check if pre_post_update works in your case.

+2
source

Source: https://habr.com/ru/post/1268152/


All Articles