Title: Polylang &#8211; get post language when using wp_insert_post
Last modified: August 30, 2016

---

# Polylang – get post language when using wp_insert_post

 *  [Giovanni Invernizzi](https://wordpress.org/support/users/giovanni-paperplane/)
 * (@giovanni-paperplane)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/polylang-get-post-language-when-using-wp_insert_post/)
 * Hello,
    I need to find post language in this function (used in functions.php)
   to set $lang and then define $slug_taccuino:
 * function automatically_name_taccuino($post_id, $post, $update) {
    $desired_type
   = ‘taccuino’; if(( !in_array( $data[‘post_status’], array( ‘draft’, ‘pending’,‘
   auto-draft’ ) ) ) && $desired_type === $post->post_type) { if ( $lang === ‘it’){
   $slug_taccuino = ‘taccuino’; } if ( $lang === ‘en’ ) { $slug_taccuino = ‘notebook’;}
   if ( $lang === ‘fr’ ) { $slug_taccuino = ‘cahier’; }
 *  $keep_title = get_the_title();
    $keep_post_id = get_the_ID(); $date_slug = get_the_date(‘
   Y-m-d’); $post_title_parts = array(); $post_title_parts[] = $keep_title; $post_title_parts[]
   = $slug_taccuino; $post_title = implode(‘ – ‘, array_filter(array_map(‘trim’,
   $post_title_parts))); $post_name = sanitize_title($post_title, $post_id); global
   $wpdb; $wpdb->update($wpdb->posts, array(‘post_name’ => $post_name), array(‘ID’
   => $post_id)); } } add_action(‘wp_insert_post’, ‘automatically_name_taccuino’,
   11, 3);
 * Any help is appreciated!

Viewing 1 replies (of 1 total)

 *  Thread Starter [Giovanni Invernizzi](https://wordpress.org/support/users/giovanni-paperplane/)
 * (@giovanni-paperplane)
 * [10 years, 7 months ago](https://wordpress.org/support/topic/polylang-get-post-language-when-using-wp_insert_post/#post-6646694)
 * Answer 🙂
 * function automatically_name_taccuino($post_id, $post, $update) {
    $desired_type
   = ‘taccuino’; if(( !in_array( $data[‘post_status’], array( ‘draft’, ‘pending’,‘
   auto-draft’ ) ) ) && $desired_type === $post->post_type) { $lang = pll_get_post_language(
   $post_id); if ( $lang === ‘it’ || $lang == ” ) { $slug_taccuino = ‘taccuino’;}
   if ( $lang === ‘en’ ) { $slug_taccuino = ‘notebook’; } if ( $lang === ‘fr’ ) {
   $slug_taccuino = ‘cahier’; }
 *  $keep_title = get_the_title();
    $keep_post_id = get_the_ID(); $date_slug = get_the_date(‘
   Y-m-d’); $post_title_parts = array(); $post_title_parts[] = $keep_title; $post_title_parts[]
   = $slug_taccuino; $post_title = implode(‘ – ‘, array_filter(array_map(‘trim’,
   $post_title_parts))); $post_name = sanitize_title($post_title, $post_id); global
   $wpdb; $wpdb->update($wpdb->posts, array(‘post_name’ => $post_name), array(‘ID’
   => $post_id)); } } add_action(‘wp_insert_post’, ‘automatically_name_taccuino’,
   11, 3);

Viewing 1 replies (of 1 total)

The topic ‘Polylang – get post language when using wp_insert_post’ is closed to 
new replies.

## Tags

 * [wp_insert_post](https://wordpress.org/support/topic-tag/wp_insert_post/)

 * 1 reply
 * 1 participant
 * Last reply from: [Giovanni Invernizzi](https://wordpress.org/support/users/giovanni-paperplane/)
 * Last activity: [10 years, 7 months ago](https://wordpress.org/support/topic/polylang-get-post-language-when-using-wp_insert_post/#post-6646694)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
