【发布时间】:2016-03-30 22:22:30
【问题描述】:
Wordpress 问题,
我有自定义帖子类型
3 分类法
每个分类中的多个术语
下面的代码将输出“Custom_Taxonomy”中的术语列表
如何让它从同一自定义帖子类型中的“Custom_Taxonomy2”中吐出列表?
$terms = get_terms( 'Custom_Taxonomy' );
echo '<ul>';
foreach ( $terms as $term ) {
// The $term is an object, so we don't need to specify the $taxonomy.
$term_link = get_term_link( $term );
// If there was an error, continue to the next term.
if ( is_wp_error( $term_link ) ) {
continue;
}
// We successfully got a link. Print it out.
echo '<li><a href="' . esc_url( $term_link ) . '">' . $term->name . '</a></li>';
}
echo '</ul>';
我一直在尝试以下解决方案,但它们都不起作用,我不是一个 php 编码器。 (请不要给我反对票,我在这里尝试:-))
$terms = get_terms( 'Custom_Taxonomy' AND 'Custom_Taxonomy2' );
$terms = get_terms( 'Custom_Taxonomy' || 'Custom_Taxonomy2' );
$terms = get_terms( 'Custom_Taxonomy' && 'Custom_Taxonomy2' );
$terms = get_terms( 'Custom_Taxonomy', 'Custom_Taxonomy2' );
$terms = get_terms( 'Custom_Taxonomy' 'Custom_Taxonomy2' );
【问题讨论】:
-
与您要获取的分类名称相同的代码?
-
呵呵,我刚刚想通了,我现在正在使用该解决方案。但我想知道是否可以使用此代码,例如 $terms = get_terms( 'Custom_Taxonomy' AND 'Custom_Taxonomy2' ); ???