Skip to content

Commit

Permalink
Update - filters
Browse files Browse the repository at this point in the history
  • Loading branch information
FalkoJoseph committed Oct 14, 2021
1 parent 68b425a commit b6c2eec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
59 changes: 43 additions & 16 deletions modules/class-wp-sweepbright-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,15 +529,12 @@ public static function sql_filter_price($args)

public static function sql_filter_plot_area($args)
{
if (
isset($args['params']['filters']['plot_area']) &&
is_numeric($args['params']['filters']['plot_area']['min']) &&
is_numeric($args['params']['filters']['plot_area']['max'])
) {
if (isset($args['params']['filters']['plot_area'])) {
$params = [
'min' => $args['params']['filters']['plot_area']['min'],
'max' => $args['params']['filters']['plot_area']['max']
];

if ($params['min'] === 0) {
$params['min'] = false;
}
Expand All @@ -546,34 +543,56 @@ public static function sql_filter_plot_area($args)
$params['max'] = false;
}

$args['posts'] = $args['posts']->andWhere('plot_area', '>', 0)
->andWhere('plot_area', '>=', $params['min'])
->andWhere('plot_area', '<=', $params['max']);
if (isset($params['min']) && is_numeric($params['min']) && isset($params['max']) && is_numeric($params['max'])) {
$args['posts'] = $args['posts']->andWhere('plot_area', '!=', 0)
->andWhere('plot_area', '>=', $params['min'])
->andWhere('plot_area', '<=', $params['max']);
}

if (empty($params['min']) && is_numeric($params['max']) && isset($params['max'])) {
$args['posts'] = $args['posts']->andWhere('plot_area', '!=', 0)
->andWhere('plot_area', '<=', $params['max']);
}

if (empty($params['max']) && is_numeric($params['min']) && isset($params['min'])) {
$args['posts'] = $args['posts']->andWhere('plot_area', '!=', 0)
->andWhere('plot_area', '>=', $params['min']);
}
}
return $args['posts'];
}

public static function sql_filter_liveable_area($args)
{
if (
isset($args['params']['filters']['liveable_area']) &&
is_numeric($args['params']['filters']['liveable_area']['min']) &&
is_numeric($args['params']['filters']['liveable_area']['max'])
) {
if (isset($args['params']['filters']['liveable_area'])) {
$params = [
'min' => $args['params']['filters']['liveable_area']['min'],
'max' => $args['params']['filters']['liveable_area']['max']
];

if ($params['min'] === 0) {
$params['min'] = false;
}

if ($params['max'] === 0) {
$params['max'] = false;
}
$args['posts'] = $args['posts']->andWhere('liveable_area', '>', 0)
->andWhere('liveable_area', '>=', $params['min'])
->andWhere('liveable_area', '<=', $params['max']);

if (isset($params['min']) && is_numeric($params['min']) && isset($params['max']) && is_numeric($params['max'])) {
$args['posts'] = $args['posts']->andWhere('liveable_area', '!=', 0)
->andWhere('liveable_area', '>=', $params['min'])
->andWhere('liveable_area', '<=', $params['max']);
}

if (empty($params['min']) && is_numeric($params['max']) && isset($params['max'])) {
$args['posts'] = $args['posts']->andWhere('liveable_area', '!=', 0)
->andWhere('liveable_area', '<=', $params['max']);
}

if (empty($params['max']) && is_numeric($params['min']) && isset($params['min'])) {
$args['posts'] = $args['posts']->andWhere('liveable_area', '!=', 0)
->andWhere('liveable_area', '>=', $params['min']);
}
}
return $args['posts'];
}
Expand Down Expand Up @@ -737,6 +756,13 @@ public static function add_marker($id, $results)
'formatted_agency' => get_post_meta($id, 'location_formatted_agency', true),
],
'image' => $image,
'images' => [
[
'sizes' => [
'medium_large' => $image,
]
]
],
'price' => get_post_meta($id, 'price_amount', true),
];

Expand Down Expand Up @@ -769,6 +795,7 @@ public static function add_estate($id, $results)
$images[]['sizes'] = [
'thumbnail' => wp_get_attachment_image_url($image, 'thumbnail'),
'medium' => wp_get_attachment_image_url($image, 'medium'),
'medium_large' => wp_get_attachment_image_url($image, 'medium'),
'large' => wp_get_attachment_image_url($image, 'large'),
];
}
Expand Down
4 changes: 2 additions & 2 deletions wp-sweepbright.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Author: Compagnon Agency
* Author URI: https://compagnon.agency/
* Text Domain: wp-sweepbright
* Version: 2.0.0
* Version: 2.0.1
*/

// If this file is called directly, abort.
Expand All @@ -23,7 +23,7 @@
* Start at version 1.0.0 and use SemVer - https://semver.org
* Rename this for your plugin and update it as you release new versions.
*/
define('WP_SWEEPBRIGHT_VERSION', '2.0.0');
define('WP_SWEEPBRIGHT_VERSION', '2.0.1');

/**
* The code that runs during plugin activation.
Expand Down

0 comments on commit b6c2eec

Please sign in to comment.