Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何从自定义字段中获取第一个术语?_Php_Wordpress_Custom Taxonomy - Fatal编程技术网

Php 如何从自定义字段中获取第一个术语?

Php 如何从自定义字段中获取第一个术语?,php,wordpress,custom-taxonomy,Php,Wordpress,Custom Taxonomy,使用wordpress,有一个自定义的分类字段“authors”,在该字段中,我为每个出版物输入多个名称,例如(马克·吐温、伊莎贝尔·拉加德、托尼·班德),当我使用以下代码时: <?php $object_terms = wp_get_object_terms($post->ID, 'auteur', array('fields' => 'all')); if ($object_terms) { echo '' . '', . '' ; $res = '';

使用wordpress,有一个自定义的分类字段“authors”,在该字段中,我为每个出版物输入多个名称,例如(马克·吐温、伊莎贝尔·拉加德、托尼·班德),当我使用以下代码时:

<?php
$object_terms = wp_get_object_terms($post->ID, 'auteur', array('fields'  => 'all'));
if ($object_terms) {
    echo '' . '', . '' ;
    $res = '';
    foreach ($object_terms as $term) {
        $res .= '' . $term->name . ', ';
    }
    echo rtrim($res,' ,').'' . '';
}
?>

我可以得到每一份出版物的所有作者的名字。
但是,我要做什么才能让代码只显示第一作者的全名?

可能是我错了。在foreach之前,只需尝试echo rtrim($object_terms->fields->name,“,”);当把它放在foreach后面时,它起作用了,但它显示了第一个单词。事实上,我需要它来显示第一个全名请你的代码正在工作。你说什么?