Bỏ qua điều hướng
availability:

WPML Version: 3.2

description:

Retrieve language information of a post by its ID.

The language information that is returned includes:

  • the post language 2-letter code,
  • the post locale,
  • the language text direction (True for RTL, False for LTR),
  • the post language translated name and native name and
  • whether the current language is different to the post language (True/False)
type:
filter
category:
Retrieving Language Information for Content
parameters:
apply_filters( 'wpml_post_language_details', mixed $empty_value, int $post_id )
$empty_value
(mixed) (Required) This is normally the value the filter will be modifying. We are not filtering anything here so set this to NULL. This for the filter function to actually receive the full argument list
$post_id
(int) (Optional) The post id to retrieve information of (post, page, attachment, custom post) Defaults to current post ID.
hook example usage:

In the example below we use the filter to retrieve the language information for the “Hello World” post.
The original language of the post is English and we have translated it to German.

Example

$my_post_language_details = apply_filters( 'wpml_post_language_details', NULL, 1 ) ;

The above will return the following on the English version of the site:

array (
 'language_code' => 'en',
 'locale' => 'en_US',
 'text_direction' => false,
 'display_name' => 'English',
 'native_name' => 'English',
 'different_language' => false,
)

If we switch to the German version of the site we will see the following:

array (
 'language_code' => 'de',
 'locale' => 'de_DE',
 'text_direction' => false,
 'display_name' => 'German',
 'native_name' => 'Deutsch',
 'different_language' => true,
)