PHP hook_views_query_alter drupal 6.x

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PHP hook_views_query_alter drupal 6.x相关的知识,希望对你有一定的参考价值。

<?php
/**
* Implementation of hook_views_query_alter().
*/
function modulename_views_query_alter(&$view, &$query) {
  if ($view->name == 'viewname') {
    $type_clause = FALSE;
    // check to see if we already have a node.type clause
    foreach ($query->where[0]['clauses'] as $clause) {
      if (substr(0, 10, $clause) == 'node.type ') {
        // yes, we do
        $type_clause = TRUE;
      }
    }
   
    // if we don't, let's OR our content types together and add a clause
    if (!$type_clause) {
      // get types from the view
      $types = $view->filter['type']->options['value'];
      // we want an OR query
      $query->where[1]['type'] = 'OR';
      // add each type in turn to the clauses and args for this query
      foreach ($types as $type) {
        $query->where[1]['clauses'][] = "node.type in ('%s')";
        $key = key($query->where[1]['clauses']);
        next($query->where[1]['clauses']);
        $query->where[1]['args'][$key] = $type;
      }
     
    }
  }
}
?>

以上是关于PHP hook_views_query_alter drupal 6.x的主要内容,如果未能解决你的问题,请参考以下文章

Drupal 视图过滤器中的 OR 运算符

linux 安装多个PHP版本(php5.6 php7.1 php7.2 php7.3 php7.4 php8.0)nginx配置php多版本

php [guzzle php] guzzle php #php

php send.php php邮件模板#php

IntelliJ IDEA 11编辑php是,支持php文件名为.php5和.php4,如何设置能让其也支持.php呢?

如何从php5升级到php7