public static function get($args = array()) { $cache = new PLS_Cache('nbh'); if ($result = $cache->get($args)) { return $result; } extract(self::process_args($args), EXTR_SKIP); $subject = array(); if ($street) { $subject += array('taxonomy' => 'street', 'term' => $street, 'api_field' => 'address'); } elseif ($neighborhood) { $subject += array('taxonomy' => 'neighborhood', 'term' => $neighborhood, 'api_field' => 'neighborhood'); } elseif ($zip) { $subject += array('taxonomy' => 'zip', 'term' => $zip, 'api_field' => 'postal'); } elseif ($city) { $subject += array('taxonomy' => 'city', 'term' => $city, 'api_field' => 'locality'); } elseif ($state) { $subject += array('taxonomy' => 'state', 'term' => $state, 'api_field' => 'region'); } $term = get_term_by('slug', $subject['term'], $subject['taxonomy'], ARRAY_A); $custom_data = array(); foreach (self::$custom_meta as $meta) { $custom_data[$meta['id']] = get_tax_meta($term['term_id'], $meta['id']); } $term = wp_parse_args($term, $custom_data); $term['api_field'] = $subject['api_field']; //if there's a polygon, use that to get listings. Otherwise, use the name of the neighborhood $polygon = PLS_Plugin_API::get_taxonomies_by_slug($subject['term']); if (is_array($polygon) && !empty($polygon[0])) { $polygon[0]['neighborhood_polygons'] = $polygon[0]['name']; $listings_raw = PLS_Plugin_API::get_polygon_listings($polygon[0]); $term['listings'] = PLS_Partials::get_listings("limit=5&context=home&neighborhood_polygons=" . $polygon[0]['name']); } else { $listings_raw = PLS_Plugin_API::get_listings("location[" . $term['api_field'] . "]=" . $term['name']); $term['listings'] = PLS_Partials::get_listings("limit=5&context=home&request_params=location[" . $term['api_field'] . "]=" . $term['name']); } $term['areas'] = array('locality' => array(), 'postal' => array(), 'neighborhood' => array(), 'address' => array()); $locality_tree = array('city' => array('postal', 'neighborhood', 'address'), 'zip' => array('neighborhood', 'address'), 'neighborhood' => array('address'), 'street' => array()); $term['listings_raw'] = $listings_raw['listings']; //assemble all the photos $api_translations = array('locality' => 'city', 'neighborhood' => 'neighborhood', 'postal' => 'zip', 'address' => 'street'); $term['listing_photos'] = array(); $count = 0; if (isset($listings_raw['listings'])) { foreach ($listings_raw['listings'] as $key => $listing) { if (!empty($listing['images'])) { foreach ($listing['images'] as $image) { if ($count > $image_limit) { break; } $term['listing_photos'][] = array('full_address' => $listing['location']['full_address'], 'image_url' => $image['url'], 'listing_url' => $listing['cur_data']['url']); $count++; } } if (isset($locality_tree[$subject['taxonomy']])) { foreach ($locality_tree[$subject['taxonomy']] as $locality) { $link = array('name' => $listing['location'][$locality], 'permalink' => get_term_link($listing['location'][$locality], $api_translations[$locality])); if (is_string($link['permalink'])) { $term['areas'][$locality][] = $link; } } } } } $term['polygon'] = PLS_Plugin_API::get_polygon_detail(array('tax' => $term['api_field'], 'slug' => $subject['term'])); $cache->save($term); return $term; }