WPML
apply_filters( 'wpml_get_element_translations', mixed $empty_value, integer $trid, string $element_type)
类型
filter
WPML 版本
3.3.5

说明

  • 使用 trid(翻译组的 ID)获取元素翻译信息。
  • trid 可以通过 wpml_element_trid 过滤器获取。
  • WPML 的表文档页面上了解有关此内容的更多信息。

参数

$empty_value
(mixed) (必填) 这通常是过滤器将要修改的值。我们在这里不进行任何过滤,因此将其设置为 NULL。这是为了让过滤器函数能够实际接收完整的参数列表。
$trid
(integer) (必填) 翻译组的 ID。
$element_type
(string) (可选) 元素的类型。可以是文章类型:post_postpost_pagepost_attachmentpost_nav_menu_itempost_{custom post key},或者是分类法:tax_categorytax_post_tagtax_nav_menutax_{custom taxonomy key}。如果未设置,则默认为 post_post

使用示例

示例
$translations = apply_filters( 'wpml_get_element_translations', NULL, 2, 'post_page' );
var_dump($translations);
/**
 * The result looks like the following 
 * 
array(2) {
  ["en"]=>
  object(stdClass)#1857 (8) {
    ["translation_id"]=>
    string(1) "1"
    ["language_code"]=>
    string(2) "en"
    ["element_id"]=>
    string(1) "2"
    ["source_language_code"]=>
    NULL
    ["element_type"]=>
    string(9) "post_page"
    ["original"]=>
    string(1) "1"
    ["post_title"]=>
    string(4) "Home"
    ["post_status"]=>
    string(7) "publish"
  }
  ["es"]=>
  object(stdClass)#1856 (8) {
    ["translation_id"]=>
    string(3) "141"
    ["language_code"]=>
    string(2) "es"
    ["element_id"]=>
    string(3) "187"
    ["source_language_code"]=>
    string(2) "en"
    ["element_type"]=>
    string(9) "post_page"
    ["original"]=>
    string(1) "0"
    ["post_title"]=>
    string(6) "Inicio"
    ["post_status"]=>
    string(7) "publish"
  }
}
 */

wpml_decode_custom_field, wpml_footer_language_selector, wpml_add_language_form_field, wpml_ls_exclude_in_menu, wpml_is_rtl, wpml_alternate_hreflang, wpml_head_langs, wpml_must_translate_canonical_url, wpml_browser_redirect_language_params, wpml_active_languages

所有 29 个 全站语言信息 钩子 →