如何解决“Invalid Taxonomy”,在WordPress页面上显示Array数组?

时间:2015-11-20 23:23:06

标签: php wordpress wordpress-plugin advanced-custom-fields custom-taxonomy

当我var_dump($term_list);

$term_list = wp_get_post_terms($post->ID, 'functiongroups', array("fields" => "names")); 

foreach ($term_list as $term) { $i++;
         echo '.$term.';
         echo ($i > 0 && !($i % 2 == 0)) ? ', ' : '';
};

我得到了这个:

WP_Error Object ([errors] => Array ([invalid_taxonomy] => Array ([0]
=> Invalid Taxonomy)) [error_data] => Array ())

,并在WordPress页面上显示Array数组,而不是预期的分类。

1 个答案:

答案 0 :(得分:0)

分类标准的名称不存在(即使用高级自定义字段或使用分类法的任何其他插件创建的分类法)或使用wp_get_post_terms();时拼写错误。 (在我的情况下,' functiongroups '不存在);

请注意,分类也可以通过编程方式添加,而不仅仅是使用插件:

function functiongroups_init() {
    // create a new taxonomy
    register_taxonomy(
        'functiongroups',
        'post',
        array(
            'label' => __( 'Functiongroups' ),
            ...
        )
    );
}
add_action( 'init', 'functiongroups_init' );