Search
 
SCRIPT & CODE EXAMPLE
 

PHP

drupal 9 modify a views query

function hook_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {

  // (Example assuming a view with an exposed filter on node title.)
  // If the input for the title filter is a positive integer, filter against
  // node ID instead of node title.
  if ($view
    ->id() == 'my_view' && is_numeric($view->exposed_raw_input['title']) && $view->exposed_raw_input['title'] > 0) {

    // Traverse through the 'where' part of the query.
    foreach ($query->where as &$condition_group) {
      foreach ($condition_group['conditions'] as &$condition) {

        // If this is the part of the query filtering on title, change the
        // condition to filter on node ID.
        if ($condition['field'] == 'node.title') {
          $condition = [
            'field' => 'node.nid',
            'value' => $view->exposed_raw_input['title'],
            'operator' => '=',
          ];
        }
      }
    }
  }
}
Comment

PREVIOUS NEXT
Code Example
Php :: php json decoding as string incorrectly 
Php :: add custom attribute for validation errors laravel 
Php :: get post in php 
Php :: Make a Woo required field not required 
Php :: hoew to store a cookie php 
Php :: get custom post type taxonomy value 
Php :: laravel route multiple methods 
Php :: error_log wordpress 
Php :: find which php.ini is used 
Php :: type hidden value put laravel 
Php :: time now with milliseconds php 
Php :: get curret timedate php 
Php :: in_array associative array php 
Php :: php remove first word from string 
Php :: laravel pagination number of items 
Php :: woocommerce checkout manager confirm password 
Php :: remove scientific notation number format in php 
Php :: yesterday php 
Php :: withdefault laravel 
Php :: add json extenstion php 
Php :: php get embed code from youtube url 
Php :: how to include file in laravel blade 
Php :: connect sql server php 
Php :: laravel use global variable in model 
Php :: laravel url download file 
Php :: php order filename 
Php :: pdf to image php 
Php :: distinct laravel not working 
Php :: config clear without artisan 
Php :: carbon between hours 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =