显示自定义分类法的所有条款?
-
-
在什么时候失败?它有多少以您想要的方式工作?At what point does this fail? How much of it works the way you'd like?
- 0
- 2014-03-04
- s_ha_dum
-
它起作用的问题是,我只能以自定义帖子类型显示SELECTED字词.我希望所有人都显示是否选择了,我不希望有一个虚拟的帖子类型仅选择所有内容来显示它们.It works the issue is that I can only show the SELECTED terms in a custom post type. I want all of them to show wether selected or not, I don't want to have a dummy post type that has everything selected just to show them.
- 0
- 2014-03-04
- David H
-
3 个回答
- 投票数
-
- 2014-03-04
您需要将其他参数传递给
get_terms()
.默认设置是隐藏"空"字词-未分配给任何帖子的字词.$terms = get_terms([ 'taxonomy' => $taxonomy, 'hide_empty' => false, ]);
You need to pass an additional argument to
get_terms()
. The default is to hide "empty" terms-- terms which are assigned to no posts.$terms = get_terms([ 'taxonomy' => $taxonomy, 'hide_empty' => false, ]);
-
非常感谢!但是我想问一下,为什么要在变量内创建一个数组而不是在显示第一个数组的上方声明它呢?Thank you so much! But I want to ask something, why would you create an array inside a variable instead of declaring it above where the first array is shown?
- 0
- 2014-03-04
- David H
-
简单.如果参数数组更复杂,我会首先(最有可能)声明它,但是对于单个参数来说,这是最简单的方法.无论哪种方式,它都应同样有效地工作.Simplicity. If the argument array were more complex I would have declared it first (most likely), but for a single argument that is just the most straightforward way to do it. It should work equally well either way.
- 0
- 2014-03-04
- s_ha_dum
-
非常感谢:)那让我很感动.我真的很感激!Thanks a lot :) that thought me a lot. I really appreciate it!
- 0
- 2014-03-04
- David H
-
作品!!现在,我可以看到所有分类法选项的内容!一些插件在其中创建复杂的结构.Works!! Now I can see what's going on with all the taxonomy options! Some plugins create complex structure in there.
- 0
- 2018-06-22
- eyal_katz
-
- 2017-07-21
从4.5.0版本开始,分类法应通过$ args数组中的"taxonomy"参数传递,因此:
$terms = get_terms( array( 'taxonomy' => 'post_tag', 'hide_empty' => false, ) );
默认情况下,没有帖子的术语会被隐藏.
Since 4.5.0, taxonomies should be passed via the ‘taxonomy’ argument in the $args array so:
$terms = get_terms( array( 'taxonomy' => 'post_tag', 'hide_empty' => false, ) );
where terms that have no posts are hidden by default.
-
- 2017-02-14
此代码使用
get_terms()
获取所有类别和子类别的自定义分类法:<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'parent' =>0)); foreach($wcatTerms as $wcatTerm) : ?> <ul> <li> <a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a> <ul class="megaSubCat"> <?php $wsubargs = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $wcatTerm->term_id, 'taxonomy' => 'product_cat' ); $wsubcats = get_categories($wsubargs); foreach ($wsubcats as $wsc): ?> <li><a href="<?php echo get_term_link( $wsc->slug, $wsc->taxonomy );?>"><?php echo $wsc->name;?></a></li> <?php endforeach; ?> </ul> </li> </ul> <?php endforeach; ?>
This code is fetches all category and subcategory custom taxonomies using
get_terms()
:<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'parent' =>0)); foreach($wcatTerms as $wcatTerm) : ?> <ul> <li> <a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a> <ul class="megaSubCat"> <?php $wsubargs = array( 'hierarchical' => 1, 'show_option_none' => '', 'hide_empty' => 0, 'parent' => $wcatTerm->term_id, 'taxonomy' => 'product_cat' ); $wsubcats = get_categories($wsubargs); foreach ($wsubcats as $wsc): ?> <li><a href="<?php echo get_term_link( $wsc->slug, $wsc->taxonomy );?>"><?php echo $wsc->name;?></a></li> <?php endforeach; ?> </ul> </li> </ul> <?php endforeach; ?>
我做了一些自定义分类法,我需要显示其中的所有术语,到目前为止,我取得的成就是显示了在自定义帖子类型中选择/选择的分类法,但是我需要所有它们来显示,是否是否选择. 这样以后我就可以创建一个过滤器,以根据自定义帖子类型值包含的术语进行过滤.
到目前为止我所拥有的.
提前谢谢!