在wordpress中获取所有类别的投资组合


Get all category of portfolio in wordpress

我是wordpress的新手。我想在页脚中显示联系人表单,在该表单中,我想放置类别的下拉列表,这些类别基本上是我的投资组合的类别。

如何获取所有投资组合类别名称?

有人能回答我吗。

提前谢谢。

在WP中,类别(组)是一个分类法,该分类法由术语(单个类别)组成。

下面的代码收集所有投资组合类别并填充一个数组,以便您可以将其用于<select>

    $select_category_arr = array();  
    $taxonomy = 'portfolio_category'; // Go to WPadmin -> Portfolio categories. Check url for correct taxonomy name.
    $terms = get_terms($taxonomy); // Get all terms of a taxonomy
    if ( $terms && !is_wp_error( $terms ) ) {
        foreach( $terms as $term ) {
            $select_category_arr[$term->slug] = $term->name;    
        }
    }

数组$select_category_arr包含所有公文包类别。