admin管理员组文章数量:1026989
I just want to know why get_object_taxonomies('custom-post-type-name')
return empty array for custom post types but works fine with post as argument : get_object_taxonomies('post')
and returns:
array (size=3)
0 => string 'category' (length=8)
1 => string 'post_tag' (length=8)
2 => string 'post_format' (length=11)
I just want to know why get_object_taxonomies('custom-post-type-name')
return empty array for custom post types but works fine with post as argument : get_object_taxonomies('post')
and returns:
array (size=3)
0 => string 'category' (length=8)
1 => string 'post_tag' (length=8)
2 => string 'post_format' (length=11)
Share
Improve this question
edited Feb 19, 2018 at 20:36
Johansson
15.4k11 gold badges43 silver badges79 bronze badges
asked Feb 19, 2018 at 18:12
geeky87geeky87
214 bronze badges
5
- Are you sure the problem is not a simple typo? – Johansson Commented Feb 19, 2018 at 20:36
- Where are you using this code? Perhaps you're outside of the Loop so there is no object it's running on? – WebElaine Commented Feb 19, 2018 at 21:42
- @JackJohansson I found the cause of this issue : the problem is that the post types isn't recognizable inside my plugin folder :/any idea ? – geeky87 Commented Feb 20, 2018 at 12:17
- @WebElaine : the problem is that the post types isn't recognizable inside my plugin folder – geeky87 Commented Feb 20, 2018 at 12:18
- As you mentioned the function works fine with an argument - have you tried passing one of the CPTs as an argument to see if that works? Hard to help without further context about where and how this code is running. – WebElaine Commented Feb 20, 2018 at 18:27
1 Answer
Reset to default 1I have run into the same issue. I believe the root cause is the order of execution. For the sake of experiment, I ran get_object_taxonomies()
immediately after register_taxonomy()
, in fact in the same function and it worked as expected. So what to do? Use add_action()
hook to execute get_object_taxonomies()
after register_taxonomy()
. The correct order of execution can be guaranteed via 3rd argument of add_action( ... int $priority = 10 ... )
I just want to know why get_object_taxonomies('custom-post-type-name')
return empty array for custom post types but works fine with post as argument : get_object_taxonomies('post')
and returns:
array (size=3)
0 => string 'category' (length=8)
1 => string 'post_tag' (length=8)
2 => string 'post_format' (length=11)
I just want to know why get_object_taxonomies('custom-post-type-name')
return empty array for custom post types but works fine with post as argument : get_object_taxonomies('post')
and returns:
array (size=3)
0 => string 'category' (length=8)
1 => string 'post_tag' (length=8)
2 => string 'post_format' (length=11)
Share
Improve this question
edited Feb 19, 2018 at 20:36
Johansson
15.4k11 gold badges43 silver badges79 bronze badges
asked Feb 19, 2018 at 18:12
geeky87geeky87
214 bronze badges
5
- Are you sure the problem is not a simple typo? – Johansson Commented Feb 19, 2018 at 20:36
- Where are you using this code? Perhaps you're outside of the Loop so there is no object it's running on? – WebElaine Commented Feb 19, 2018 at 21:42
- @JackJohansson I found the cause of this issue : the problem is that the post types isn't recognizable inside my plugin folder :/any idea ? – geeky87 Commented Feb 20, 2018 at 12:17
- @WebElaine : the problem is that the post types isn't recognizable inside my plugin folder – geeky87 Commented Feb 20, 2018 at 12:18
- As you mentioned the function works fine with an argument - have you tried passing one of the CPTs as an argument to see if that works? Hard to help without further context about where and how this code is running. – WebElaine Commented Feb 20, 2018 at 18:27
1 Answer
Reset to default 1I have run into the same issue. I believe the root cause is the order of execution. For the sake of experiment, I ran get_object_taxonomies()
immediately after register_taxonomy()
, in fact in the same function and it worked as expected. So what to do? Use add_action()
hook to execute get_object_taxonomies()
after register_taxonomy()
. The correct order of execution can be guaranteed via 3rd argument of add_action( ... int $priority = 10 ... )
本文标签: plugin developmentgetobjecttaxonomies() returns empty array for custom post type
版权声明:本文标题:plugin development - get_object_taxonomies() returns empty array for custom post type 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745525179a2154492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论