pll_get_post

Among the post and its translations, returns the id of the post which is in the language represented by $slug.

Description

(int|false|null) pll_get_post( (int) $post_id, (string) $slug = '' ); 

Returns (int|false|null)

post id of the translation if exists, false otherwise, null if the current language is not defined yet

Parameters (2)

0. $post_id (int)
The post id.
1. $slug — Optional. (string) => ''
Language code, defaults to current language

Usage

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

Defined (1)

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

/include/api.php  
  1. function pll_get_post( $post_id, $slug = '' ) { 
  2. return ( $slug = $slug ? $slug : pll_current_language() ) ? PLL()->model->post->get( $post_id, $slug ) : null;