This commit is contained in:
Hoang Huu
2020-06-18 11:09:45 +07:00
parent 22c65f696a
commit 4fe7aecb30
19 changed files with 176 additions and 93 deletions

View File

@@ -483,7 +483,7 @@ class Opalestate_Property_MetaBox {
public function metaboxes_layout_fields() {
$prefix = OPALESTATE_PROPERTY_PREFIX;
$templates = opalestate_single_layout_prieview();
$templates = opalestate_single_layout_preview();
$fields = [
[

View File

@@ -319,12 +319,11 @@ class Opalestate_Query {
}
if ( isset( $args['featured'] ) && $args['featured'] ) {
$args = array_merge( $args,
[
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'meta_value' => 'on',
'meta_compare' => '=',
] );
$args = array_merge( $args, [
'meta_key' => OPALESTATE_PROPERTY_PREFIX . 'featured',
'meta_value' => 'on',
'meta_compare' => '=',
] );
unset( $args['featured'] );
}
@@ -342,17 +341,21 @@ class Opalestate_Query {
}
/**
*
* Filter_by_location
*/
public static function filter_by_location( $geo_lat, $geo_long, $radius, $prefix = OPALESTATE_PROPERTY_PREFIX ) {
public static function filter_by_location( $geo_lat, $geo_long, $radius, $radius_measure = '', $prefix = OPALESTATE_PROPERTY_PREFIX ) {
global $wpdb;
$radius_measure = '';
$earth = 3959;
if ( $radius_measure == 'km' ) {
$earth = 6371;
switch ( $radius_measure ) {
case 'km':
$earth = 6371;
break;
case 'miles':
$earth = 3959;
break;
default :
$earth = 6371;
break;
}
$latitude = $prefix . 'map_latitude';
@@ -382,7 +385,6 @@ class Opalestate_Query {
ORDER BY $wpdb->posts.menu_order ASC, distance ASC";
$query = $wpdb->prepare( $sql,
$earth,
$geo_lat,
$geo_long,

View File

@@ -288,10 +288,10 @@ class OpalEstate_Search {
'compare' => 'LIKE',
'operator' => 'OR',
];
} elseif ( $_GET['geo_lat'] && $_GET['geo_long'] ) {
$radius = isset( $_GET['geo_radius'] ) ? $_GET['geo_radius'] : 5;
$post_ids = Opalestate_Query::filter_by_location( $_GET['geo_lat'], $_GET['geo_long'], $radius );
$radius_measure = isset( $_GET['radius_measure'] ) ? sanitize_text_field( $_GET['radius_measure'] ) : 'km';
$radius = isset( $_GET['geo_radius'] ) ? sanitize_text_field( $_GET['geo_radius'] ) : 10;
$post_ids = Opalestate_Query::filter_by_location( sanitize_text_field( $_GET['geo_lat'] ), sanitize_text_field( $_GET['geo_long'] ), $radius_measure, $radius );
$args['post__in'] = $post_ids;
}
}