简体   繁体   English

wp_get_object_terms返回空

[英]wp_get_object_terms returns empty

I have taxonomy called mh_menu. 我有一个名为mh_menu的分类法。 I want to get terms for object, and for it I'm using wp_get_object_terms. 我想获取对象的术语,为此我正在使用wp_get_object_terms。 When I do 当我做

wp_get_object_terms(639, 'mh_menu', array('fields' => 'all', 
'orderby' => 'none'));

I get result with terms array 我得到了术语数组的结果

WP_Term Object                                                                                                        
(                                                                                               
[term_id] => 118
[name] => new cat
[slug] => new-cat
[term_group] => 0
[term_taxonomy_id] => 118
[taxonomy] => mh_menu
[description] => 
[parent] => 0
[count] => 2
[filter] => raw
)

and etc 等等

but When I do 但是当我这样做

wp_get_object_terms(639, 'mh_menu', array('fields' => 'tt_ids', 
'orderby' => 'none'));

I get empty array 我得到空数组

Array
(
)

And the most interesting thing that I have two wordpress sites (all is up to date) and in first site it's working but in the second site it's returning empty array. 最有趣的是,我有两个wordpress网站(所有网站都是最新的),在第一个网站上它可以工作,但是在第二个网站上,它返回空数组。

Try my code and let me know what you are getting in the count in the printed array. 试试我的代码,让我知道您在打印数组中获得的数量。

wp_get_object_terms(639, 'mh_menu', array('fields' => 'tt_ids', 'orderby' => 'none','hide_empty' => false));

If you found 0 than please add the post to respective category and revert your code back as this is the simple default wordpress behavior. 如果发现0,那么请将帖子添加到相应的类别,然后还原代码,因为这是简单的默认wordpress行为。

If your category is not map to the post wordpress default not allowing you to display that category. 如果您的类别未映射到post wordpress默认值,则不允许您显示该类别。 If you still wish to show that category than you need to pass the hide_empty as a false in your argument. 如果您仍然希望显示该类别,则需要在变量中传递hide_empty作为false

I've found the solution, the problem was from hierarchy. 我找到了解决方案,问题出在层次结构上。 I've deleted whole term, and recreated, so the information for hierarchy was right, and all worked! 我删除了整个术语,然后重新创建,因此有关层次结构的信息是正确的,并且一切正常!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM