繁体   English   中英

在 Wordpress 中获取没有明确分类法 ID 的自定义分类法的条款

[英]Get the terms of a custom taxonomy without explicit taxonomy IDs in Wordpress

我使用以下代码进行了尝试,但它不起作用。 我需要为这个明确的帖子保存的分类法的所有条款。 但我只得到“数组”。

get_the_terms( $post->ID, 'regisseur', 'Regisseur: <span class="flight">

另外我想除了 ID 43 和 76 – 这些术语不应显示在列表中。

为什么它不起作用?

如果您需要获取帖子中的所有术语,则应使用wp_get_post_terms () 而不是 get_the_terms()

尝试这个

<?php

$terms = wp_get_post_terms($post->ID, 'regisseur');
if ($terms)
{
    $output = array();
    foreach ($terms as $term) {
    //Here we exclude terms
    if ($term->term_id == 43) continue;
    if ($term->term_id == 76) continue;

            $output[] = '<span><a href="' . get_term_link($term->slug, 'regisseur') . '">' . $term->name . '</a></span>';    

    }
    echo join(' ', $output);
};
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM