在做了大量的修改之后,我设法使功能正常工作。
首先,我使用wp的操作为“区域”和“国际”添加自定义下拉框restrict_manage_posts
. 然后我设置了一个自定义函数,该函数将添加到wp的过滤器中parse_query
.
在该功能中:
// type is the name of the select field
if($_GET[\'type\'] == \'Regional\'){
// get terms as WP_Term objects
$regional_terms_objects = get_terms( array(
\'taxonomy\' => \'regional\',
\'hide_empty\' => false,
));
// convert them to an array of slugs
$regional_terms_objects = array();
foreach ($regional_terms_objects as $regional_terms_object){
$regional_terms[] = $regional_terms_object->slug;
}
// filter the posts by all terms for taxonomy
$tax_query = array(
\'taxonomy\' => \'event-categories\',
\'field\' => \'slug\',
\'terms\' => $regional_terms
);
}else{
// the same stuff for \'International\'
}
// add the query
$query->set(\'tax_query\', $tax_query);
这样,我就可以在admin视图中选择“Regional”和“International”,只查看属于所选分类法的事件。我希望有人可以使用它:)