特别感谢对我最后两个问题的每一个答复,我还有另外两个重要的问题: first:我需要下一个代码来从我的自定义帖子类型的一个特定分类中获取元术语。我尝试将 array('fields' => 'all') 替换为 array('fields' => 'proceeding') 以仅从正在进行的分类法中获取元术语,但它不起作用。有什么建议吗? 第二:有没有办法让代码在获取所有分类法中的所有术语时,根据不同的分类法在不同行上显示术语?
foreach ((array) get_object_taxonomies($post->post_type) as $taxonomy) {
$object_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields' => 'all'));
if ($object_terms) {
echo ': (- ' . $taxonomy . ': ';// I modify the output a bit.
$res = '';
foreach ($object_terms as $term) {
$res .= '<a href="' . esc_attr(get_term_link($term, $taxonomy)) . '" title="' . sprintf(__("View all posts in %s"), $term->name) . '" ' . '>' . $term->name . '</a>, ';
}
echo rtrim($res,' ,').')';// I remove the last trailing comma and space and add a ')'
}
}
如果您只需要“进行中”分类法中的术语,您可以使用:
$object_terms = wp_get_object_terms($post->ID, 'proceeding');
您关于将事物放在不同线上的问题并不完全清楚。如果你只是添加
'<br />'
在字符串末尾,那么下一个将换行。