[英]get_terms() showing error for plugin taxonomy
I have this code in wordpress plugin folder, localhost/wp-content/plugins/test/cat.php
我在wordpress插件文件夹
localhost/wp-content/plugins/test/cat.php
有此代码
<?
define( "WP_INSTALLING", true );
require ('../../../wp-blog-header.php');
$categories = get_terms("ad_cat","parent=6&hide_empty=0");
print_r($categories);
?>
But, this is displaying an error as: 但是,这显示为以下错误:
WP_Error Object
(
[errors] => Array
(
[invalid_taxonomy] => Array
(
[0] => Invalid Taxonomy
)
)
[error_data] => Array
(
)
)
But, there isn't any error when I did the same thing in sidebar widget using PHP code plugin. 但是,当我使用PHP代码插件在侧边栏小部件中执行相同的操作时,没有任何错误。 Taxonomy
ad_cat
exists, that is created automatically using Wordpress Classifieds Theme. 存在分类法
ad_cat
,它是使用Wordpress分类主题自动创建的。 That works when I use taxonomy category
which is default category of wordpress. 当我使用分类
category
这是wordpress的默认类别)时,该方法有效。 But, I want it to display of ad_cat
但是,我希望它显示
ad_cat
Remove define( "WP_INSTALLING", true );
删除
define( "WP_INSTALLING", true );
and that will solve the project. 这将解决该项目。 That worked for me.
那对我有用。
Wordpress adds plugin files before any theme file added. WordPress会在添加任何主题文件之前添加插件文件。 So simply you cant get theme modified data in plugin.
因此,您根本无法在插件中获取主题修改的数据。
So, you have to wait for theme file to be added. 因此,您必须等待主题文件被添加。
Consider add_action
and add_hook
to hook your custom function. 考虑使用
add_action
和add_hook
来挂接您的自定义函数。 That will make every data available in your custom function 这将使您自定义函数中的所有数据可用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.