WordPress、get_categories、分类法

发布于 2024-12-13 19:25:04 字数 218 浏览 0 评论 0原文

我有一个非常简单的问题,WordPress Codex 上没有回答。

get_categories() 函数获取分类法选项。我想问的是,我可以通过多个这样的分类法吗:

get_categories(
    array(
        'taxonomies' => 'category,my_custom_taxonomy'
    )
);

I have a very simple question that is not answered on WordPress Codex.

The get_categories() function get an option for taxonomies. What I like to ask is, can I pass more than one taxonomies like that:

get_categories(
    array(
        'taxonomies' => 'category,my_custom_taxonomy'
    )
);

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

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

发布评论

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

评论(1

時窥 2024-12-20 19:25:04

get_categories 函数仅允许为分类参数输入字符串(1 个分类)。

您可以使用 get_terms ,它允许一系列分类法。

$args = array( 'taxonomies' => array( 'tax_1', 'tax_2', 'tax_3') );

$categories = get_terms ( $args );

for each ( $categories as $cat ) :

  var_dump( $cat );

endforeach;

The get_categories function only allows a string (1 taxonomy) to be entered for the taxonomy arg.

You can use get_terms which allows an array of taxonomies.

$args = array( 'taxonomies' => array( 'tax_1', 'tax_2', 'tax_3') );

$categories = get_terms ( $args );

for each ( $categories as $cat ) :

  var_dump( $cat );

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