public static function argTaxQuery(Query $query, $value, &$q)
{
$currentValue = $value;
$function = function (Query $query) use(&$currentValue, &$function) {
foreach ($currentValue as $key => $tax) {
if ($key === 'relation') {
continue;
}
if (!isset($tax[0]) || !is_array($tax[0])) {
// not nested
$include_children = !isset($tax['include_children']) || $tax['include_children'] != false;
$compare = empty($tax['operator']) ? 'in' : $tax['operator'];
$terms = $tax['terms'];
if (is_string($terms)) {
if (strpos($terms, '+') !== false) {
$terms = preg_split('/[+]+/', $terms);
} else {
$terms = preg_split('/[,]+/', $terms);
}
}
switch ($tax['field']) {
case 'term_id':
$query->where("terms.{$tax['taxonomy']}.term_id", $compare, $terms);
if ($include_children) {
$query->where("terms.{$tax['taxonomy']}.parent", $compare, $terms);
}
break;
case 'slug':
if ($include_children) {
$query->where("terms.{$tax['taxonomy']}.all_slugs", $compare, $terms);
} else {
$query->where("terms.{$tax['taxonomy']}.slug", $compare, $terms);
}
break;
case 'name':
// plugin exclusive feature.
$query->where("terms.{$tax['taxonomy']}.name", $compare, $terms);
break;
}
} else {
// nested
$currentValue = $tax;
$query->bool($function, !empty($currentValue['relation']) ? $currentValue['relation'] : 'and');
}
}
};
$query->bool($function, !empty($value['relation']) ? $value['relation'] : 'and');
}