diff options
Diffstat (limited to 'engine/lib/metadata.php')
-rw-r--r-- | engine/lib/metadata.php | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/engine/lib/metadata.php b/engine/lib/metadata.php index 1d6fc59f4..ea1ce412d 100644 --- a/engine/lib/metadata.php +++ b/engine/lib/metadata.php @@ -571,23 +571,25 @@ function elgg_get_entities_from_metadata(array $options = array()) { $clauses = elgg_get_entity_metadata_where_sql('e', $options['names'], $options['values'], $options['name_value_pairs'], $options['name_value_pairs_operator'], $options['case_sensitive']); - // merge wheres to pass to get_entities() - if (isset($options['wheres']) && !is_array($options['wheres'])) { - $options['wheres'] = array($options['wheres']); - } elseif (!isset($options['wheres'])) { - $options['wheres'] = array(); - } + if ($clauses) { + // merge wheres to pass to get_entities() + if (isset($options['wheres']) && !is_array($options['wheres'])) { + $options['wheres'] = array($options['wheres']); + } elseif (!isset($options['wheres'])) { + $options['wheres'] = array(); + } - $options['wheres'][] = $clauses['wheres']; + $options['wheres'] = array_merge($options['wheres'], $clauses['wheres']); - // merge joins to pass to get_entities() - if (isset($options['joins']) && !is_array($options['joins'])) { - $options['joins'] = array($options['joins']); - } elseif (!isset($options['joins'])) { - $options['joins'] = array(); - } + // merge joins to pass to get_entities() + if (isset($options['joins']) && !is_array($options['joins'])) { + $options['joins'] = array($options['joins']); + } elseif (!isset($options['joins'])) { + $options['joins'] = array(); + } - $options['joins'] = array_merge($options['joins'], $clauses['joins']); + $options['joins'] = array_merge($options['joins'], $clauses['joins']); + } return elgg_get_entities($options); } @@ -629,6 +631,8 @@ function elgg_get_entity_metadata_where_sql($table, $names = NULL, $values = NUL 'wheres' => array() ); + $wheres = array(); + // get names wheres and joins $names_where = ''; if ($names !== NULL) { @@ -758,7 +762,9 @@ function elgg_get_entity_metadata_where_sql($table, $names = NULL, $values = NUL } } - $return['wheres'] = implode(' OR ', $wheres); + if ($where = implode(' OR ', $wheres)) { + $return['wheres'][] = "($where)"; + } return $return; } |