【发布时间】:2022-01-27 09:11:09
【问题描述】:
我创建了一个名为国籍的自定义分类法,然后我添加它以让用户通过使用 ACF 的自定义帐户编辑表单选择他/她的国籍。
我正在尝试将 Tax 值输入 Author.php 页面,但它返回为 Array , 这是我正在使用的代码:
<?php
$curauth = (isset($_GET['author_name'])) ? get_user_by('slug', $author_name) : get_userdata(intval($author));
$terms = wp_get_post_terms($post->ID, 'nationality' , $curauth);
if ($terms){
$out = array(
'name'=>'<span>Nationality: </span>'
);
foreach ($terms as $term)
{
$out[] = '<a " ' . ' href="' . esc_url(get_term_link( $term->slug, 'nationality')) .'">' .$term->name .'</a>' ;}
echo join( ' ', $out );
}
?>
我也试过下面的代码:
<?php
$nationality = get_field('nationality', $curauth);
$nationality = get_field_object('nationality', $curauth);
echo $nationality['value'];
?>
仍然给我一个数组。
字段类型为 select 且 Return Value 设置为 Term Object 或 Term ID 那么错误是 WP_Term 类的对象无法转换为字符串
任何想法如何使它正确。
谢谢! 艾哈迈德
【问题讨论】:
-
如果正确,请将我的答案标记为正确,请... =)
标签: wordpress advanced-custom-fields custom-taxonomy author