我正在尝试为自定义帖子类型创建一个父ID列表,以便在我正在项目上开发的“必须使用”插件中使用。
下面是我用来生成查询的代码:
$cpt_parents = new WP_Query( array (
\'post_type\' => \'cpt\',
\'posts_per_page\' => -1, // Get them all
\'post_parent\' => 0, // Return only top-level
\'fields\' => \'ids\'
)
);
$parent_ids = $cpt_parents->posts;
以下是产生的错误:
Notice: Undefined index: wp_taxonomies in [url]/wp-includes/query.php on line 1700
Warning: Invalid argument supplied for foreach() in [url]/wp-includes/query.php on line 1700
Notice: Undefined index: wp_taxonomies in [url]/wp-includes/query.php on line 1700
Warning: Invalid argument supplied for foreach() in [url]/wp-includes/query.php on line 1700
Fatal error: Call to undefined function is_user_logged_in() in [url]/wp-includes/query.php on line 2485
在插件中运行WP\\u查询需要做什么?
最合适的回答,由SO网友:Jonathan Wold 整理而成
我想出来了。我将对WP Alchemy的引用移动到一个在init之后激发的函数中。现在一切都很好,我可以在安装文件中使用WP\\u Query。
以下是代码参考:
// WP Alchemy Setup
function jd_setup_wp_alchemy() {
include_once WPMU_PLUGIN_DIR . \'/jonathanwold/metaboxes/setup.php\';
include_once WPMU_PLUGIN_DIR . \'/jonathanwold/metaboxes/cpt-spec.php\';
}
add_action(\'init\', \'jd_setup_wp_alchemy\');