modules/custom/your_module/your_module.module
/** * @param \Drupal\views\ViewExecutable $view * @param \Drupal\views\Plugin\views\query\QueryPluginBase $query */ function your_module_views_query_alter(ViewExecutable $view, QueryPluginBase $query) { if ($view->id() == 'your_view_id') { $or = new Condition('OR'); foreach ($条件 as $_and) { $and = new Condition('AND'); foreach ($_and as $key => $val) { if (!empty($val)) { $and->condition("node__{$key}.{$key}_value", $val); } } $or->condition($and); } $query->addWhere($whereGroup++, $or); } }