Last active
December 30, 2015 00:09
-
-
Save Apina/7748039 to your computer and use it in GitHub Desktop.
EE Modified search
this should be added to the Custom files addon (custom_shortcodes) as it is a separate shortcode
It allows expired events to be disregarded from the search results
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Search | |
//Shortcode to create an autocomplete search tool. | |
function ee_create_autocomplete_search2($atts){ | |
$a = shortcode_atts( array( | |
'show_expired' => 'false' | |
), $atts ); | |
global $wpdb, $espresso_manager, $current_user, $org_options; | |
$array = array('ee_search' => 'true'); | |
$url = add_query_arg($array, get_permalink($org_options['event_page_id'])); | |
ob_start(); | |
?> | |
<div id="espresso-search-form-dv" class="ui-widget"> | |
<form name="form" method="post" action="<?php echo $url ?>"> | |
<input id="ee_autocomplete" name="ee_name" class="ui-autocomplete-input ui-corner-all" /> | |
<input id="ee_search_submit" name="ee_search_submit" class="ui-button ui-button-big ui-priority-primary ui-state-default ui-state-hover ui-state-focus ui-corner-all" type="submit" value="Search" /> | |
<input id="event_id" name="event_id" type="hidden"> | |
</form> | |
</div> | |
<?php | |
$ee_autocomplete_params = array(); | |
$todaysdate = date('y-m-d'); | |
$SQL = "SELECT e.*"; | |
if ( isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ) { | |
$SQL .= ", v.city venue_city, v.state venue_state, v.name venue_name, v.address venue_address, v.city venue_city, v.state venue_state, v.zip venue_zip, v.country venue_country, v.meta venue_meta "; | |
} | |
$SQL .= " FROM " . EVENTS_DETAIL_TABLE . " e "; | |
if ( isset($org_options['use_venue_manager']) && $org_options['use_venue_manager'] == 'Y' ) { | |
$SQL .= " LEFT JOIN " . EVENTS_VENUE_REL_TABLE . " vr ON vr.event_id = e.id LEFT JOIN " . EVENTS_VENUE_TABLE . " v ON v.id = vr.venue_id "; | |
} | |
$SQL .= " WHERE e.is_active = 'Y' "; | |
$SQL .= " AND e.event_status != 'D' "; | |
if($a['show_expired'] == 'false') { | |
$SQL .= " AND DATE(e.registration_end) >= CURDATE() "; | |
} | |
//echo '<p>$sql = '.$sql.'</p>'; | |
$events = $wpdb->get_results($SQL); | |
$num_rows = $wpdb->num_rows; | |
if ($num_rows > 0) { | |
foreach ($events as $event){ | |
$venue_city = !empty($event->venue_city) ? stripslashes_deep($event->venue_city) : ''; | |
$venue_state = !empty($event->venue_state) ? (!empty($event->venue_city) ? ', ' : '') .stripslashes_deep($event->venue_state) : ''; | |
$venue_name = !empty($event->venue_name) ?' @' . stripslashes_deep($event->venue_name) . ' - ' . $venue_city . $venue_state . '' : ''; | |
//An Array of Objects with label and value properties: | |
$ee_autocomplete_params[] = array( | |
'url' => espresso_reg_url($event->id), | |
'value' => stripslashes_deep($event->event_name) . $venue_name, | |
'id' => $event->id | |
); | |
//echo '{ url:"'.espresso_reg_url($event->id).'", value: "'.stripslashes_deep($event->event_name) . $venue_name .'", id: "'.$event->id.'" },'; | |
} | |
} | |
wp_register_script('espresso_autocomplete', (EVENT_ESPRESSO_PLUGINFULLURL . "scripts/espresso_autocomplete.js"), array( 'jquery-ui-autocomplete' ), '1.0.0', TRUE ); | |
wp_enqueue_script('espresso_autocomplete'); | |
wp_localize_script( 'espresso_autocomplete', 'ee_autocomplete_params', $ee_autocomplete_params ); | |
//Load scripts | |
add_action('wp_footer', 'ee_load_jquery_autocomplete_scripts'); | |
$buffer = ob_get_contents(); | |
ob_end_clean(); | |
return $buffer; | |
} | |
add_shortcode('EVENT_SEARCH2', 'ee_create_autocomplete_search2'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated it to exclude expired events by default, if show_expired="true" parameter is set, expired events will show in the listing.