get_terms(get_the_ID) 显示 WP_Error
get_terms(get_the_ID) shows WP_Error
我试图从 post 中显示我的自定义分类标签,但它 returns NULL 或 WP_Error
var_dump(get_terms(get_the_ID()));
// Returns this
object(WP_Error)#6268 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(20) "Taxonomia inválida." } } ["error_data"]=> array(0) { } }
为什么这样说它的分类法无效?
您使用了错误的功能,get_terms
将 return 列出分类法中的术语。如果要列出包含自定义分类法的 post 的术语,则需要使用 get_the_terms
var_dump( get_the_terms(get_the_ID(), 'your-custom-taxonomy');
https://developer.wordpress.org/reference/functions/get_the_terms/
我试图从 post 中显示我的自定义分类标签,但它 returns NULL 或 WP_Error
var_dump(get_terms(get_the_ID()));
// Returns this
object(WP_Error)#6268 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(20) "Taxonomia inválida." } } ["error_data"]=> array(0) { } }
为什么这样说它的分类法无效?
您使用了错误的功能,get_terms
将 return 列出分类法中的术语。如果要列出包含自定义分类法的 post 的术语,则需要使用 get_the_terms
var_dump( get_the_terms(get_the_ID(), 'your-custom-taxonomy');
https://developer.wordpress.org/reference/functions/get_the_terms/