pll_get_post_language

Returns the post language.

Description

(bool|string) pll_get_post_language( (int) $post_id, (string) $field = 'slug' ); 

Returns (bool|string)

the requested field for the post language, false if no language is associated to that post

Parameters (2)

0. $post_id (int)
The post id.
1. $field — Optional. (string) => 'slug'
The language field to return name,, locale, defaults to slug

Usage

  1. if ( !function_exists( 'pll_get_post_language' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'polylang/include/api.php'; 
  3.  
  4. // The post id. 
  5. $post_id = -1; 
  6.  
  7. // optional the language field to return 'name', 'locale', defaults to 'slug' 
  8. $field = 'slug'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pll_get_post_language($post_id, $field); 
  12.  

Defined (1)

The function is defined in the following location(s).

/include/api.php  
  1. function pll_get_post_language( $post_id, $field = 'slug' ) { 
  2. return ( $lang = PLL()->model->post->get_language( $post_id ) ) ? $lang->$field : false;