Classi press advanced search
I am looking into adding the advanced search to the home page. Where is the database tables for the zipcode search in phpmyadmin? Is it referencing google maps longitude and latitude? or where is it referencing the zip_code database?
in the classipress folder search.php
function custom_search_refine_where( $where ) {
global $wpdb, $wp_query, $refine_count, $cp_options;
$refine_count = 0; // count how many post meta we query
$old_where = $where; // intercept the old where statement
if ( is_search() && isset( $_GET['s'] ) && isset( $_GET['refine_search'] ) ) {
$query = '';
$price_set = false;
foreach ( $_GET as $key => $value ) {
if ( empty( $value ) ) {
continue;
}
switch ( $key ) {
case 'cp_city_zipcode' :
$region = $cp_options->gmaps_region;
$value = urlencode( $value );
$geocode = json_decode( wp_remote_retrieve_body( wp_remote_get( "http://maps.googleapis.com/maps/api/geocode/json?address=$value®ion=$region" ) ) );
if ( 'OK' == $geocode->status ) {
$wp_query->set( 'search_geo_query', array(
'lat' => $geocode->results[0]->geometry->location->lat,
'lng' => $geocode->results[0]->geometry->location->lng,
'rad' => intval( $_GET['distance'] ),
) );
} else {
// Google Maps API error
}
break;
case 'amount' :
case 'price_min' :
case 'price_max' :
if ( $price_set ) {
break;
}
$price_set = true;
$refine_count++;
if ( $cp_options->refine_price_slider ) {
$value = str_replace( array( $cp_options->curr_symbol, ' ' ), '', $value );
$value = str_replace( ' ', '', $value );
$value = explode( '-', $value );
} else {
$price_min = empty( $_GET['price_min'] ) ? 0 : (int) $_GET['price_min'];
$price_max = empty( $_GET['price_max'] ) ? 9999999999 : (int) $_GET['price_max'];
$value = array( $price_min, $price_max );
}
$query .= " AND (";
$query .= "(mt" . $refine_count . ".meta_key = 'cp_price')";
$query .= " AND (CAST(mt" . $refine_count . ".meta_value AS SIGNED) BETWEEN '$value[0]' AND '$value[1]')";
$query .= ")";
break;
default :
if ( 'cp_' == substr( $key, 0, 3 ) ) {
$field = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->cp_ad_fields WHERE field_name = %s", $key ) );
if ( $field === null ) {
break;
}
$refine_count++;
if ( is_array( $value ) ) {
$value = implode( "','", $value );
}
$compare = ( in_array( $field->field_type, array( 'radio', 'checkbox', 'drop-down' ) ) ) ? "IN ('$value')" : "LIKE '%$value%'";
$query .= " AND (";
$query .= "(mt" . $refine_count . ".meta_key = '$key')";
$query .= " AND (CAST(mt" . $refine_count . ".meta_value AS CHAR) $compare)";
$query .= ")";
}
break;
}
}
$geo_query = $wp_query->get( 'search_geo_query' );
if ( $geo_query ) {
extract( $geo_query, EXTR_SKIP );
$R = ( 'mi' == $cp_options->distance_unit ) ? 3959 : 6371;
$query .= $wpdb->prepare( " AND ( %d * acos( cos( radians(%f) ) * cos( radians(lat) ) * cos( radians(lng) - radians(%f) ) + sin( radians(%f) ) * sin( radians(lat) ) ) ) < %d", $R, $lat, $lng, $lat, $rad );
}
if ( ! empty( $query ) ) {
$where .= $query;
}
remove_filter( 'posts_where', 'custom_search_refine_where' );
Attached Images