欢迎各位兄弟 发布技术文章
这里的技术是共享的
$where =& $query->conditions();
... but the object(s) within are utterly confusing, and I've been struggling to remove or replace existing snippets. I've explored /includes/select.inc and /includes/query.inc but the classes therein don't seem to provide any methods for fine-tune manipulation.
思路是
$where =& $query->conditions(); // Remove the second condition.
unset($where[1]); //根据$where值 进行相应的unset
//也许是unset($where[1]['arg'][1]) unset($where[1]['clauses'][1])
来自 http://drupal.stackexchange.com/questions/30685/how-do-i-remove-the-where-clause-from-a-structured-q...
I would like to remove the where clause for the city and postal_code filter field. I found the code below for D6 but it's not working.
<?php
function distprox_mini_views_query_alter(&$view, &$query) {
if ($view->name == 'search' && $view->current_display == 'page_3') {
// Remove the exposed filter conditions from the WHERE clause (WHERE city = MyCityInput)
// and remove the corresponding args that were passed via the exposed filters
// This effectively turns the city and zip code exposed filters into just text fields
// that get used in distprox_mini_exposed_filter_proximity();
$city = $view->exposed_raw_input['city'];
$zip = $view->exposed_raw_input['postal_code'];
// Remove the city or zip arguments (from the exposed filters)
foreach ($query->where[0]['args'] as $key => $arg) {
if ($arg == $city || $arg == $zip) {
unset($query->where[0]['args'][$key]);
}
}
// Remove the corresponding WHERE clause additions
foreach ($query->where[0]['clauses'] as $key => $clause) {
if (strpos($clause, 'postal_code') !== FALSE || strpos($clause, 'city') !== FALSE) {
unset($query->where[0]['clauses'][$key]);
}
}
}
}
?>
来自 https://www.drupal.org/node/1567520
Comments
Comment#1
fehin CreditAttribution: fehin commentedIt was a lot easier than I thought. I dsm the query and did it like below. Not sure it's the perfect way to do it but it's working.
Comment#2
jenlampton CreditAttribution: jenlampton as a volunteer and at Jeneration Web Development for America's Best Bootfitters commentedI'm seeing Cannot access protected property SelectQuery::$where. Guessing things have changed a bit since 2012 :)
edit: looks like the where is now buried a bit deeper, something more like this...