I am attempting to add some "OR" statements to my Drupal view (to accomodate a grouping of taxonomy terms).
I am able to replace a tid one for one without an issue using the following code:
function customedm_views_query_alter(&$view, &$query) {
if ($view->name == 'course_catalog') {
dpm($query);
foreach($query->where[1]['conditions'] as &$condition){
if ($condition['value'] == 422){
$condition['value'] = 311;
}
}
}
}
The problem is, I need to replace this value with several values (311,316,and 326)
I've tried replacing the $conditions variable with the proper or statement e.g.:
$condition = "WHERE field_data_field_course_subject.field_course_subject_tid = '311' OR field_data_field_course_subject.field_course_subject_tid = '326'";
Or creating a second $query->where[] array with the seemingly appropriate entries into the array:
function customedm_views_query_alter(&$view, &$query) {
if ($view->name == 'course_catalog') {
dpm($query);
foreach($query->where[1]['conditions'] as &$condition){
if ($condition['value'] == 422){
$newconditions = array(
conditions => array(
array(
field => 'field_data_field_course_subject.field_course_subject_tid',
value => 311,
operator => '='
),
array(
field => 'field_data_field_course_subject.field_course_subject_tid',
value => 326,
operator => '='
),
array(
field => 'field_data_field_course_subject.field_course_subject_tid',
value => 316,
operator => '='
)
),
args => array(),
type => "OR"
);
$query->where[] = $newconditions;
}
}
}
}
Neither of these approaches seem to product the desired outcome (though I was able to verify that the array creating approach created the appropriate fields in $view->query... can someone show me how I can add OR statements to my query using this hook?
$query->where[0]['type'] = 'OR';
– iLLin Feb 14 '17 at 17:24$query->where[1]['conditions'][0]['field'] = "subject = 311 OR subject = 316";
(subject IN (311,316) maybe do that. I've done that before to get control. – iLLin Feb 14 '17 at 17:32$condition['field'] = "WHERE field_data_field_course_subject.field_course_subject_tid = '311' OR field_data_field_course_subject.field_course_subject_tid = '326'";
and$condition['field'] = "field_data_field_course_subject.field_course_subject_tid IN (311,316,326)";
With no success. Grouping from within the views UI is not working for whatever reason (I started there). The OR operator from within the view itself won't really help me unless I want to add another display into the mix (I dont) --appreciate the thought though. – dougblitz210 Feb 14 '17 at 19:16