function terms_by_id($ids, $taxonomy = NULL) { global $wpdb, $wf; if (!is_array($ids)) { $ids = explode(",", $ids); } $results = array(); if (count($ids)) { // check for composite IDs $ids_by_taxonomy = array(); foreach ($ids as $id) { list($term_taxonomy, $term_id) = WOOF::parse_term_composite($id); if (!is_null($taxonomy)) { $term_taxonomy = $taxonomy; } if (!isset($ids_by_taxonomy[$term_taxonomy])) { $ids_by_taxonomy[$term_taxonomy] = array($term_id); } else { $ids_by_taxonomy[$term_taxonomy][] = $term_id; } } // build the where clause $where_parts = array(); foreach ($ids_by_taxonomy as $tax_name => $ids) { $real_ids = array(); foreach ($ids as $id) { if (is_numeric($id)) { $real_ids[] = $id; } } if (count($real_ids)) { $where = " ( t.term_id IN (".implode(",", $real_ids)." ) "; if ($tax_name != "*") { $where .= " AND tt.taxonomy = '".$tax_name."' "; } $where .= " ) "; $where_parts[] = $where; } } if (count($where_parts)) { $sql = "SELECT t.term_id, t.name, t.slug, t.term_group, tt.term_taxonomy_id, tt.count, tt.description, tt.parent, tt.taxonomy FROM $wpdb->terms t INNER JOIN $wpdb->term_taxonomy tt ON tt.term_id = t.term_id WHERE ( ".implode(" OR ", $where_parts)." ) "; $results = $wpdb->get_results($sql); } } return $wf->wrap_terms($results); }