php - 在 WPML 中注册的 ACF 选择
问题描述
由于 WPML 不提供翻译[choices]
字段的解决方案,我想添加一个自定义函数来在 WPML 中注册它,但是我不是 php 中的明星,但我有以下但它没有在 WPML 字符串翻译中注册它:
$field = get_field_object( 'type_of_property' ); // acf field with choices
if (!empty($field['choices'])) {
foreach( $field['choices'] as $choice ){
do_action( 'wpml_register_single_string', 'ACF Domain', 'name'.$choice , $choice );
$acflabel= apply_filters( 'wpml_translate_single_string', $choice, 'ACF Domain', 'name'.$choice, NULL );
echo ' - ' . $acflabel;
}
}
上述方法是否朝着正确的方向发展,还是我需要调用该type_of_property
领域内的所有选择?
解决方案
我相信你应该能够做到这一点:
$field = get_field_object( 'type_of_property' );
if ( !empty( $field['choices'] ) ) {
foreach( $field['choices'] as $choice ){
echo ' - ' . __( $choice, 'ACF Domain' );
}
}
然后扫描您的主题/插件中的字符串:
- 在管理仪表板中,转到WPML > 主题和插件本地化
- 选择主题或插件,然后单击以扫描它。
- 扫描完成后,您应该能够在“字符串翻译”页面上找到字符串。
文件:
推荐阅读
- tomcat - 如何在 WildFly 11 上部署类文件?
- web3 - 使用 web3js 在 Quorum 上发送签名交易以进行合同交互
- javascript - Web USB:更改接口状态的操作正在进行错误
- python - 我正在尝试在 matplotlib 中绘制 35 个图,但输出非常小
- compilation - Jmodelica 界面在模拟模型时自动关闭
- google-api - Google API 在未经验证的应用程序中撤销了授权
- python - 从列表列表中选择三个列表的最有效方法,使得所有列表中唯一元素的数量组合大于阈值
- python - plot() 使用 ssh -X 连接到显示
- sockets - 使用 netlink 套接字时不需要轮询,为什么?
- javascript - 如何将焦点移动到Vuejs中的下一个输入字段?