解决了它,使用pre_get_posts
过滤器和WP_Query->set()
方法
function foo_filter_orders($query) {
global $pagenow;
$qv = &$query->query_vars;
$currentUserRoles = wp_get_current_user()->roles;
if (in_array(\'shop_manager\', $currentUserRoles)) {
if ( $pagenow == \'edit.php\' &&
isset($qv[\'post_type\']) && $qv[\'post_type\'] == \'shop_order\' ) {
$query->set(\'meta_key\', \'handle_by\');
$query->set(\'meta_value\', \'shopmanager1\');
}
}
return $query;
}
add_filter(\'pre_get_posts\', \'foo_filter_orders\');