Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/12.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 - Fatal编程技术网

Php 列出自定义帖子类型中的多个分类法

Php 列出自定义帖子类型中的多个分类法,php,wordpress,Php,Wordpress,Wordpress问题 我有自定义的邮件类型 3分类法 以及每个分类中的多个术语 下面的代码将列出“自定义_分类法”中的术语列表 如何让它在同一自定义帖子类型中从“Custom_Taxonomy2”中吐出列表 $terms = get_terms( 'Custom_Taxonomy' ); echo '<ul>'; foreach ( $terms as $term ) { // The $term is an object, so we don't need to s

Wordpress问题

我有自定义的邮件类型

3分类法

以及每个分类中的多个术语

下面的代码将列出“自定义_分类法”中的术语列表

如何让它在同一自定义帖子类型中从“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>';

要获取多个分类法的结果,只需将一个数组传递到name字段中

  $terms = get_terms( array( 'Custom_Taxonomy', 'Custom_Taxonomy2'), $args ); 

和您要获取的分类名称相同的代码?呵呵,我刚刚发现了,我现在正在使用该解决方案。。但是我想知道是否可以像$terms=get_terms('Custom_Taxonomy'和'Custom_Taxonomy2')???这是可行的,在wordpress的开发者页面上,它一直就在我面前,我只是没有大脑让数组发挥作用。。谢谢你的解决方案,大卫!有一个问题,如果有两个来自不同分类法的术语,,,具有相同的名称,,,,这有什么不利之处吗?或者它会把两个名字都吐出来吗?它们是两个不同的术语,所以它会同时输出两个。您可能需要考虑一下您的体系结构,一个术语应该包含在两种分类法中吗?不可能!嗯,帖子类型叫做会议,然后我有三个分类法,叫做“城市1”“城市2”“城市3”,每个城市都有自己的部门术语,其中一些分类法与其他分类法的名称相同。。。。我认为我做的架构是正确的,如果没有请建议:-)这取决于你自己,我不知道你的项目,但一般来说,你可以有一个位置税和另一个部门的条款。这样就不会有重复,如果需要,您可以通过访问标签页面查看所有城市的部门标签帖子
  $terms = get_terms( array( 'Custom_Taxonomy', 'Custom_Taxonomy2'), $args );