Error: Call to a member function addWhere() on array in hook_views_query_alter() I'm getting the error 'Call to a member function addWhere() on array' in my hook. 
Any thoughts? 
I just need to add WHERE clause to my query.

use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;

/**
 * Implementation of hook_views_query_alter
 *
 * @param $view
 * @param $query
 */   
function MYMODULE_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view-&gt;id() == 'search_filter' &amp;&amp; $view-&gt;getDisplay()-&gt;display['id'] == 'block_1') {
    $field = 'node__field_country.field_country_target_id';
    $value = 'somevalue';
    $operator = '=';
    $query-&gt;addWhere(0, $field, $value, $operator);
Try to add your condition to conditions array in the where  $query-&gt;where like the following:

/**
 * Implements hook_views_query_alter().
 */
function myModule_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {
  if ($view-&gt;id() === 'search_filter' &amp;&amp; $view-&gt;current_display === 'block_1') {
    $field = 'node__field_country.field_country_target_id';
    $value = 'someValue';
    $operator = '=';
    if (isset($query-&gt;where[1]['conditions'])) {
      $query-&gt;where[1]['conditions'][] = [
        "field"    =&gt; $field,
        "value"    =&gt; $value,
        "operator" =&gt; $operator,
      ];
    }
  }
}


Read this Article it's very useful.