[+] Mark translations as needing update after editing post from front-end with Toolset Form

When editing a post in the back end its existing translations get marked as requiring an update. That doesn’t happen if the post is edited using a front-end Toolset Form.

Add the following snippet to ensure that it does.

add_action( 'cred_save_data', 'wpmlsupp_update_status', 10, 2 );
function wpmlsupp_update_status( $post_id, $form_data ){
 
    if ( in_array( $form_data['id'], array( 123, 456 ) ) ){
 
        $post = get_post( $post_id );
         
        // get translations
        $trid = apply_filters( 'wpml_element_trid', NULL, $post_id, 'post_'.$post->post_type );
        $translations = apply_filters( 'wpml_get_element_translations', NULL, $trid, 'post_'.$post->post_type );
         
        // convert translations to comma-separated list of translation_ids
        if ( $translations ){
            $current_lang = apply_filters( 'wpml_current_language', NULL );
             
            $translation_ids = array();
 
            foreach ($translations as $lang => $translation){
                if ( $lang != $current_lang ){
                    $translation_ids[] = $translation->translation_id;
                }
            }
            $translation_ids_list = implode( ",", $translation_ids );
             
            // update table wp_icl_translation_status column needs_update
            global $wpdb;
            $update = "UPDATE {$wpdb->prefix}icl_translation_status SET needs_update=1 WHERE translation_id IN ({$translation_ids_list})";
            $result = $wpdb->query( $update );
        }
    }
}

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments