Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created July 3, 2012 14:15
Show Gist options
  • Save joshfeck/3039981 to your computer and use it in GitHub Desktop.
Save joshfeck/3039981 to your computer and use it in GitHub Desktop.
espresso venue city shortcode
// derived from espresso_venue_sc
if (!function_exists('espresso_venue_city_sc')) {
function espresso_venue_city_sc($atts) {
global $wpdb, $this_event_id;
empty($atts) ? '' : extract($atts);
$FROM = " FROM ";
$order_by = isset($order_by) && $order_by != '' ? " ORDER BY " . $order_by . " ASC " : " ORDER BY name ASC ";
$limit = $limit > 0 ? " LIMIT 0," . $limit . " " : '';
$using_id = false;
//Find the event id
if (isset($id) && $id > 0) {
} elseif (isset($event_id)) {
$event_id = $event_id; //Check to see if the event is used in the shortcode parameter
$using_id = true;
} elseif (isset($this_event_id)) {
$event_id = $this_event_id; //Check to see if the global event id is being used
$using_id = true;
} elseif (isset($_REQUEST['event_id'])) {
$event_id = $_REQUEST['event_id']; //If the first two are not being used, then get the event id from the url
$using_id = true;
}
$sql = "SELECT ev.* ";
if ($using_id == true) {
$sql .= " $FROM " . EVENTS_DETAIL_TABLE . " e ";
$sql .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON e.id = vr.event_id ";
$FROM = " LEFT JOIN ";
}
$sql .= " $FROM " . EVENTS_VENUE_TABLE . " ev ";
if ($using_id == true) {
$sql .= " ON vr.venue_id = ev.id ";
}
if (isset($id) && $id > 0) {
$sql .= " WHERE ev.id = '" . $id . "' ";
} elseif (isset($event_id) && $event_id > 0) {
$sql .= " WHERE e.id ='" . $event_id . "' ";
} else {
$sql .= " GROUP BY ev.name ";
}
if ($using_id == false) {
$sql .= $order_by;
$sql .= $limit;
}
//echo $sql ;
$venues = $wpdb->get_results($sql);
$num_rows = $wpdb->num_rows;
if ($num_rows > 0) {
$html = '';
foreach ($venues as $venue) {
$venue_id = $venue->id;
$meta = unserialize($venue->meta);
//build the html
$html .= $venue->city != '' ? '<span class="city">' . stripslashes_deep($venue->city) . '</span>' : '';
}
}
return $html ;
}
}
add_shortcode('ESPRESSO_VENUE_CITY', 'espresso_venue_city_sc');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment