WPML 筆記

常數

  
ICL_LANGUAGE_CODE當前語言的Code
ex:zh-hant、ja、en

Functions

獲取預設語言碼

global $sitepress;
$sitepress->get_default_language());

由翻譯文章取得主要與言文章id

$element_id
(int) (Required) The ID of the post type (post, page, attachment, custom post) or taxonomy term (tag, category, custom taxonomy) to filter
$element_type
(string) (Required) The type of element the ID belongs to. Can be post, page, {custom post type key}, nav_menu, nav_menu_item, category, post_tag, {custom taxonomy key}
$return_original_if_missing
(bool) (Optional) If set to true it will always return a value (the original value, if translation is missing) Default is FALSE
$ulanguage_code
(mixed) (Optional) If missing or NULL, it will use the current language. If set to a language code, it will return a translation for that language code or the original if the translation is missing and $return_original_if_missing is set to TRUE. Default is NULL

 
echo apply_filters( 'wpml_object_id', get_the_ID(), 'page', TRUE , 'zh-hant' );

echo apply_filters( 'wpml_object_id', get_the_ID(), 'page', TRUE , ICL_LANGUAGE_CODE );
// will return the post ID in the current language for post ID 1
echo apply_filters( 'wpml_object_id', 1, 'post' );
 
// will return the category ID in the current language for categoy ID 4. If the translation is missing it will return the original (here: category ID 4)
echo apply_filters( 'wpml_object_id', 4, 'category', TRUE  );
 
// will return the German attachment ID for attachment ID 25. If the translation is missing it will return NULL
echo apply_filters( 'wpml_object_id', 25, 'attachment', FALSE, 'de' );
<?php
	$object_id = apply_filters( 'wpml_object_id', 528 , 'page' , FALSE , ICL_LANGUAGE_CODE );
	$post_url = get_page_link($object_id);
?>

Ajax

WPML Ajax url

<?php echo admin_url("admin-ajax.php?lang=". ICL_LANGUAGE_CODE); ?>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料