Created
February 1, 2013 12:11
-
-
Save joshmoto/4690958 to your computer and use it in GitHub Desktop.
functions.php
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 | |
function dealer_search_fn(){ | |
check_ajax_referer( 'dealer_search', 'nonce' ); | |
$ajaxCounty = $_POST['varCounty']; | |
$ajaxTown = $_POST['varTown']; | |
$dealerResults = new WP_Query(array( | |
'post_type' => 'dealer', | |
'meta_query' => array( | |
array( | |
'key' => 'dealer_country', | |
'value' => $ajaxCounty, | |
'compare' => '=' | |
), | |
array( | |
'key' => 'dealer_location', | |
'value' => $ajaxTown, | |
'compare' => '=' | |
) | |
) | |
)); | |
if ($dealerResults->have_posts()) : | |
echo '<div class="dealer-wrapper">'; | |
while ($dealerResults->have_posts()) : $dealerResults->the_post(); | |
global $post; | |
$dealer_id = get_post_meta($post->ID, 'dealer_ref_number', true); | |
$dealer_address1 = get_post_meta($post->ID, 'dealer_address_1', true); | |
$dealer_address2 = get_post_meta($post->ID, 'dealer_address_2', true); | |
$dealer_address3 = get_post_meta($post->ID, 'dealer_address_3', true); | |
$dealer_address4 = get_post_meta($post->ID, 'dealer_address_4', true); | |
$dealer_location = get_post_meta($post->ID, 'dealer_location', true); | |
$dealer_zipcode = get_post_meta($post->ID, 'dealer_zip_code', true); | |
$dealer_country = get_post_meta($post->ID, 'dealer_country', true); | |
$dealer_tel = get_post_meta($post->ID, 'dealer_telephone_1', true); | |
$dealer_email = get_post_meta($post->ID, 'dealer_email_1', true); | |
$dealer_web = get_post_meta($post->ID, 'dealer_web_1', true); | |
$google_map = 'http://maps.google.com/?q='.urlencode($dealer_country.', '.$dealer_zipcode.', '.$dealer_location); | |
echo '<div class="dealer-listing" id="dealer-'.$dealer_id.'">'; | |
echo '<div id="dealer-map-'.$dealer_id.'" class="mini-map" onclick="window.open(\''.$google_map.'\',\'popup\');"></div>'; | |
echo '<h1>'.get_the_title().'</h1>'; | |
// echo '<a href="'.$google_map.'" class="btn alignright" target="_blank">'.__('Map and directions','theme').'</a>'; | |
echo '<ul class="address">'; | |
if($dealer_address1) { | |
echo '<li>' . str_replace(', ', '<br />', $dealer_address1) . '</li>'; | |
} | |
if($dealer_address2) { | |
echo '<li>' . str_replace("\r", '', $dealer_address2) . '</li>'; | |
} | |
if($dealer_address3) { | |
echo '<li>' . str_replace("\r", '', $dealer_address3) . '</li>'; | |
} | |
if($dealer_address4) { | |
echo '<li>' . str_replace("\r", '', $dealer_address4) . '</li>'; | |
} | |
if($dealer_location) { | |
echo '<li>' . str_replace("\r", '', $dealer_location) . '</li>'; | |
} | |
if($dealer_zipcode) { | |
echo '<li>' . str_replace("\r", '', $dealer_zipcode) . '</li>'; | |
} | |
if($dealer_country) { | |
echo '<li>' . str_replace("\r", '', $dealer_country) . '</li>'; | |
} | |
echo '</ul>'; | |
echo '<ul class="contact-info">'; | |
if($dealer_tel) { | |
echo '<li>'.__('Telephone','theme').': <span>' . str_replace("\r", '', $dealer_tel) . '</span></li>'; | |
} | |
if($dealer_email) { | |
echo '<li>'.__('E-mail','theme').': <span><a href="mailto:' . str_replace("\r", '', $dealer_email) . '" title="' . str_replace("\r", '', $dealer_email) . '" target="_blank">' . str_replace("\r", '', $dealer_email) . '</a></span></li>'; | |
} | |
if($dealer_web) { | |
echo '<li>'.__('Website','theme').': <span><a href="http://' . str_replace("http://", '', $dealer_web) . '" title="' . str_replace("http://", '', $dealer_web) . '" target="_blank">' . str_replace("http://", '', $dealer_web) . '</a></span></li>'; | |
} | |
echo '<li><span><a href="'.$google_map.'" title="" target="_blank">'.__('Map and directions','theme').'</a></span></li>'; | |
echo '</ul>'; | |
echo $dealer_full; | |
{ ?><script type="text/javascript"> | |
$(function(){ | |
$('#dealer-map-<?php echo $dealer_id; ?>').gmap3({ | |
getlatlng:{ | |
address: "<?php echo $dealer_country.', '.$dealer_zipcode.', '.$dealer_location; ?>", | |
callback: function(results){ | |
if ( !results ) return; | |
$(this).gmap3({ | |
map:{ | |
options:{ | |
center: results[0].geometry.location, | |
zoom: 10, | |
scrollwheel: false, | |
mapTypeControl: false, | |
navigationControl: false, | |
streetViewControl: false | |
} | |
}, | |
marker:{ | |
latLng:results[0].geometry.location | |
} | |
}); | |
} | |
} | |
}); | |
}); | |
</script><?php } | |
echo '</div>'; | |
endwhile; | |
echo '</div>'; | |
unset($dealerResults); | |
endif; | |
die; | |
} | |
add_action('wp_ajax_dealer_search', 'dealer_search_fn'); | |
add_action('wp_ajax_nopriv_dealer_search', 'dealer_search_fn'); | |
function dealer_sort($a, $b){ if ($a == $b) { return 0; } return ($a < $b) ? -1 : 1; } | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment