WordPress:获取附加特定自定义分类法的自定义帖子类型的类别

发布于 2024-10-20 02:44:07 字数 422 浏览 6 评论 0原文

基本上我有一个自定义的“产品”帖子类型,它附加了两个分类法......正常的“类别”和一个称为“品牌”的自定义分类法。

我有一个特定于“品牌”的页面。在此页面上,我想列出其中包含“产品”的所有“类别”,并附有我所附的“品牌”页面的术语。

例如。假设我在“耐克”页面上。我希望它列出所有包含“产品”且附加“耐克”“品牌”的类别。

我最初的想法是使用 get_categories 但现在有方法来定义特定的分类法或“品牌”吗?

$categories = get_categories('orderby=name&depth=1&hide_empty=0&child_of='.$cat);

有人以前做过这个或者知道直接查询数据库以获得所需结果的方法吗?

非常感谢任何帮助,谢谢

Basically I have a custom post type of 'products' which has two taxonomies attached to it...the normal 'category' and a custom taxonomy called 'brands'.

I have a page which is 'brand' specific. On this page I'd like to list all the 'categories' that have a 'product' in them with a term of the 'brand' whos page I'm on attached.

Eg. say I'm on the "Nike" page. I want it to list all categories that have a 'product' in them with the 'brand' of "Nike" attached to them.

My initial thoughts are to use get_categories but theres now way to define a specific taxonomy or 'brand'?

$categories = get_categories('orderby=name&depth=1&hide_empty=0&child_of='.$cat);

Anyone done this before or knows a way to query the database directly to get the required results?

Any help is much appreicated, Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久光 2024-10-27 02:44:07

我意识到这是一个较旧的问题,但如果有人在寻找答案时偶然发现这个问题(就像我所做的那样), get_categories() 现在将本机执行此操作。请注意“分类法”=> $args 数组中的“分类类型”。只需提供注册的分类名称即可覆盖类别的默认值。

$args = array(
'type'                     => 'post',
'child_of'                 => 0,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '',
'include'                  => '',
'number'                   => '',
'taxonomy'                 => 'category',
'pad_counts'               => false );

http://codex.wordpress.org/Function_Reference/get_categories

I realize this is an older question, but in case anyone stumbles across this question while looking for an answer (as I did), get_categories() will now do this natively. Note the 'taxonomy' => 'taxonomy-type' in the $args array. Simply provide the registered taxonomy name to override the default value of category.

$args = array(
'type'                     => 'post',
'child_of'                 => 0,
'parent'                   => '',
'orderby'                  => 'name',
'order'                    => 'ASC',
'hide_empty'               => 1,
'hierarchical'             => 1,
'exclude'                  => '',
'include'                  => '',
'number'                   => '',
'taxonomy'                 => 'category',
'pad_counts'               => false );

http://codex.wordpress.org/Function_Reference/get_categories

我不咬妳我踢妳 2024-10-27 02:44:07

对于延迟,我们深表歉意。设法在以下链接的 WordPress 堆栈交换上对其进行排序(对于有相同问题的任何人):https://wordpress.stackexchange.com/questions/10998/get-categories-for-custom-post-type-with-a-specific-custom -分类法附加

sorry about the delay. managed to sort it on the Wordpress stack exchange at the following link (for anyone who has the same issue): https://wordpress.stackexchange.com/questions/10998/get-categories-for-custom-post-type-with-a-specific-custom-taxonomy-attached

一绘本一梦想 2024-10-27 02:44:07

据我所知,您不能将 get_categories () 函数与“自定义帖子类型”和“自定义分类法”一起使用。

在此站点上,您可以找到有关如何使用“自定义分类法”的好教程
http://net.tutsplus.com/tutorials/wordpress/介绍-wordpress-3-custom-taxonomies/

在“在各个页面上显示分类法分类”这一点下,必须找到您问题的解决方案。

To my knowledge, you cant use the get_categories () function with "Custom Post Types" and "Custom Taxonomies".

On this site you can find a good tutorial in how to use "Custom Taxonomies"
http://net.tutsplus.com/tutorials/wordpress/introducing-wordpress-3-custom-taxonomies/.

Under the point "Displaying Taxonomy Classifications on Individual Pages" there would have to the solution for your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文