| 1 |
<?php |
| 2 |
/** |
| 3 |
* Contains the query functions for PropertyHive which alter the front-end post queries and loops. |
| 4 |
* |
| 5 |
* @class PH_Query |
| 6 |
* @version 1.0.0 |
| 7 |
* @package PropertyHive/Classes |
| 8 |
* @category Class |
| 9 |
* @author PropertyHive |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 13 |
|
| 14 |
if ( ! class_exists( 'PH_Query' ) ) : |
| 15 |
|
| 16 |
/** |
| 17 |
* PH_Query Class |
| 18 |
*/ |
| 19 |
class PH_Query { |
| 20 |
|
| 21 |
/** @public array Query vars to add to wp */ |
| 22 |
public $query_vars = array(); |
| 23 |
|
| 24 |
/** @public array Unfiltered property ids (before layered nav etc) */ |
| 25 |
public $unfiltered_property_ids = array(); |
| 26 |
|
| 27 |
/** @public array Filtered property ids (after layered nav) */ |
| 28 |
public $filtered_property_ids = array(); |
| 29 |
|
| 30 |
/** @public array Filtered property ids (after layered nav, per taxonomy) */ |
| 31 |
public $filtered_property_ids_for_taxonomy = array(); |
| 32 |
|
| 33 |
/** @public array property IDs that match the layered nav + price filter */ |
| 34 |
public $post__in = array(); |
| 35 |
|
| 36 |
/** @public array The meta query for the page */ |
| 37 |
public $meta_query = ''; |
| 38 |
|
| 39 |
/** @public array Post IDs matching layered nav only */ |
| 40 |
public $layered_nav_post__in = array(); |
| 41 |
|
| 42 |
/** @public array Stores post IDs matching layered nav, so price filter can find max price in view */ |
| 43 |
public $layered_nav_property_ids = array(); |
| 44 |
|
| 45 |
/** |
| 46 |
* Constructor for the query class. Hooks in methods. |
| 47 |
* |
| 48 |
* @access public |
| 49 |
*/ |
| 50 |
public function __construct() { |
| 51 |
|
| 52 |
//add_action( 'init', array( $this, 'add_endpoints' ) ); |
| 53 |
add_action( 'init', array( $this, 'layered_nav_init' ) ); |
| 54 |
add_action( 'init', array( $this, 'price_filter_init' ) ); |
| 55 |
|
| 56 |
if ( ! is_admin() ) { |
| 57 |
add_action( 'init', array( $this, 'get_errors' ) ); |
| 58 |
add_filter( 'query_vars', array( $this, 'add_query_vars'), 0 ); |
| 59 |
add_action( 'parse_request', array( $this, 'parse_request'), 0 ); |
| 60 |
add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); |
| 61 |
add_filter( 'the_posts', array( $this, 'the_posts' ), 11, 2 ); |
| 62 |
add_action( 'wp', array( $this, 'remove_property_query' ) ); |
| 63 |
add_action( 'wp', array( $this, 'remove_ordering_args' ) ); |
| 64 |
} |
| 65 |
|
| 66 |
$this->init_query_vars(); |
| 67 |
} |
| 68 |
|
| 69 |
/** |
| 70 |
* Init query vars by loading options. |
| 71 |
*/ |
| 72 |
public function init_query_vars() { |
| 73 |
// Query vars to add to WP |
| 74 |
$this->query_vars = array( |
| 75 |
|
| 76 |
); |
| 77 |
} |
| 78 |
|
| 79 |
/** |
| 80 |
* Get any errors from querystring |
| 81 |
*/ |
| 82 |
public function get_errors() { |
| 83 |
if ( ! empty( $_GET['ph_error'] ) && ( $error = sanitize_text_field( $_GET['ph_error'] ) ) && ! ph_has_notice( $error, 'error' ) ) |
| 84 |
ph_add_notice( $error, 'error' ); |
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Add endpoints for query vars |
| 89 |
*/ |
| 90 |
public function add_endpoints() { |
| 91 |
foreach ( $this->query_vars as $key => $var ) |
| 92 |
add_rewrite_endpoint( $var, EP_PAGES ); |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* add_query_vars function. |
| 97 |
* |
| 98 |
* @access public |
| 99 |
* @param array $vars |
| 100 |
* @return array |
| 101 |
*/ |
| 102 |
public function add_query_vars( $vars ) { |
| 103 |
foreach ( $this->query_vars as $key => $var ) |
| 104 |
$vars[] = $key; |
| 105 |
|
| 106 |
return $vars; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Get query vars |
| 111 |
* @return array() |
| 112 |
*/ |
| 113 |
public function get_query_vars() { |
| 114 |
return $this->query_vars; |
| 115 |
} |
| 116 |
|
| 117 |
/** |
| 118 |
* Parse the request and look for query vars - endpoints may not be supported |
| 119 |
*/ |
| 120 |
public function parse_request() { |
| 121 |
global $wp; |
| 122 |
|
| 123 |
// Map query vars to their keys, or get them if endpoints are not supported |
| 124 |
foreach ( $this->query_vars as $key => $var ) { |
| 125 |
if ( isset( $_GET[ $var ] ) ) { |
| 126 |
$wp->query_vars[ $key ] = sanitize_text_field( wp_unslash( $_GET[ $var ] ) ); |
| 127 |
} |
| 128 |
|
| 129 |
elseif ( isset( $wp->query_vars[ $var ] ) ) { |
| 130 |
$wp->query_vars[ $key ] = $wp->query_vars[ $var ]; |
| 131 |
} |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Hook into pre_get_posts to do the main property query |
| 137 |
* |
| 138 |
* @access public |
| 139 |
* @param mixed $q query object |
| 140 |
* @return void |
| 141 |
*/ |
| 142 |
public function pre_get_posts( $q ) { |
| 143 |
// We only want to affect the main query |
| 144 |
if ( ! $q->is_main_query() ) |
| 145 |
return; |
| 146 |
|
| 147 |
// Fix for verbose page rules |
| 148 |
if ( $GLOBALS['wp_rewrite']->use_verbose_page_rules && isset( $q->queried_object->ID ) && $q->queried_object->ID == ph_get_page_id( 'search_results' ) ) { |
| 149 |
$q->set( 'post_type', 'property' ); |
| 150 |
$q->set( 'page', '' ); |
| 151 |
$q->set( 'pagename', '' ); |
| 152 |
|
| 153 |
// Fix conditional Functions |
| 154 |
$q->is_archive = true; |
| 155 |
$q->is_post_type_archive = true; |
| 156 |
$q->is_singular = false; |
| 157 |
$q->is_page = false; |
| 158 |
} |
| 159 |
|
| 160 |
// When orderby is set, WordPress shows posts. Get around that here. |
| 161 |
if ( ($q->is_home() || $q->get( 'page_id' ) == get_option('page_on_front')) && 'page' == get_option('show_on_front') && get_option('page_on_front') == ph_get_page_id('search_results') ) |
| 162 |
{ |
| 163 |
$_query = wp_parse_args( $q->query ); |
| 164 |
if ( empty( $_query ) || ! array_diff( array_keys( $_query ), array( 'preview', 'page', 'paged', 'cpage', 'orderby' ) ) ) |
| 165 |
{ |
| 166 |
|
| 167 |
$q->is_page = true; |
| 168 |
$q->is_home = false; |
| 169 |
$q->set( 'page_id', (int) get_option('page_on_front') ); |
| 170 |
$q->set( 'post_type', 'property' ); |
| 171 |
} |
| 172 |
} |
| 173 |
|
| 174 |
// Special check for sites with the property search results on front page |
| 175 |
if ( $q->is_page() && 'page' == get_option( 'show_on_front' ) && $q->get('page_id') == ph_get_page_id('search_results') ) { |
| 176 |
|
| 177 |
// This is a front-page property listings |
| 178 |
$q->set( 'post_type', 'property' ); |
| 179 |
$q->set( 'page_id', '' ); |
| 180 |
if ( isset( $q->query['paged'] ) ) |
| 181 |
$q->set( 'paged', $q->query['paged'] ); |
| 182 |
|
| 183 |
// Define a variable so we know this is the front page search results later on |
| 184 |
define( 'SEARCH_RESULTS_IS_ON_FRONT', true ); |
| 185 |
|
| 186 |
// Get the actual WP page to avoid errors and let us use is_front_page() |
| 187 |
// This is hacky but works. Awaiting http://core.trac.wordpress.org/ticket/21096 |
| 188 |
global $wp_post_types; |
| 189 |
|
| 190 |
$search_results_page = get_post( ph_get_page_id('search_results') ); |
| 191 |
$q->is_page = true; |
| 192 |
|
| 193 |
$wp_post_types['property']->ID = $search_results_page->ID; |
| 194 |
$wp_post_types['property']->post_title = $search_results_page->post_title; |
| 195 |
$wp_post_types['property']->post_name = $search_results_page->post_name; |
| 196 |
$wp_post_types['property']->post_type = $search_results_page->post_type; |
| 197 |
$wp_post_types['property']->ancestors = get_ancestors( $search_results_page->ID, $search_results_page->post_type ); |
| 198 |
|
| 199 |
// Fix conditional Functions like is_front_page |
| 200 |
$q->is_singular = false; |
| 201 |
$q->is_post_type_archive = true; |
| 202 |
$q->is_archive = true; |
| 203 |
|
| 204 |
// Fix WP SEO |
| 205 |
if ( class_exists( 'WPSEO_Meta' ) ) { |
| 206 |
add_filter( 'wpseo_metadesc', array( $this, 'wpseo_metadesc' ) ); |
| 207 |
add_filter( 'wpseo_metakey', array( $this, 'wpseo_metakey' ) ); |
| 208 |
} |
| 209 |
|
| 210 |
} else { |
| 211 |
|
| 212 |
// Only apply to property categories, the property post archive, the search results page, and property attribute taxonomies |
| 213 |
if ( ! $q->is_post_type_archive( 'property' ) && ! $q->is_tax( get_object_taxonomies( 'property' ) ) ) |
| 214 |
return; |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
$this->property_query( $q ); |
| 219 |
|
| 220 |
if ( is_search() ) |
| 221 |
{ |
| 222 |
add_filter( 'posts_where', array( $this, 'search_post_excerpt' ) ); |
| 223 |
add_filter( 'wp', array( $this, 'remove_posts_where' ) ); |
| 224 |
} |
| 225 |
|
| 226 |
add_filter( 'posts_where', array( $this, 'exclude_protected_properties' ) ); |
| 227 |
|
| 228 |
// We're on a property search page so queue the propertyhive_get_properties_in_view function |
| 229 |
//add_action( 'wp', array( $this, 'get_properties_in_view' ), 2); |
| 230 |
|
| 231 |
// And remove the pre_get_posts hook |
| 232 |
$this->remove_property_query(); |
| 233 |
} |
| 234 |
|
| 235 |
/** |
| 236 |
* search_post_excerpt function. |
| 237 |
* |
| 238 |
* @access public |
| 239 |
* @param string $where (default: '') |
| 240 |
* @return string (modified where clause) |
| 241 |
*/ |
| 242 |
public function search_post_excerpt( $where = '' ) { |
| 243 |
/*global $wp_the_query; |
| 244 |
|
| 245 |
// If this is not a PH Query, do not modify the query |
| 246 |
if ( empty( $wp_the_query->query_vars['ph_query'] ) || empty( $wp_the_query->query_vars['s'] ) ) |
| 247 |
return $where; |
| 248 |
|
| 249 |
$where = preg_replace( |
| 250 |
"/post_title\s+LIKE\s*(\'\%[^\%]+\%\')/", |
| 251 |
"post_title LIKE $1) OR (post_excerpt LIKE $1", $where );*/ |
| 252 |
|
| 253 |
return $where; |
| 254 |
} |
| 255 |
|
| 256 |
/** |
| 257 |
* Prevent password protected properties appearing in the loops |
| 258 |
* |
| 259 |
* @param string $where |
| 260 |
* @return string |
| 261 |
*/ |
| 262 |
public function exclude_protected_properties( $where ) { |
| 263 |
global $wpdb; |
| 264 |
$where .= " AND {$wpdb->posts}.post_password = ''"; |
| 265 |
return $where; |
| 266 |
} |
| 267 |
|
| 268 |
/** |
| 269 |
* wpseo_metadesc function. |
| 270 |
* Hooked into wpseo_ hook already, so no need for function_exist |
| 271 |
* |
| 272 |
* @access public |
| 273 |
* @return string |
| 274 |
*/ |
| 275 |
public function wpseo_metadesc() { |
| 276 |
return WPSEO_Meta::get_value( 'metadesc', ph_get_page_id('search_results') ); |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
/** |
| 281 |
* wpseo_metakey function. |
| 282 |
* Hooked into wpseo_ hook already, so no need for function_exist |
| 283 |
* |
| 284 |
* @access public |
| 285 |
* @return string |
| 286 |
*/ |
| 287 |
public function wpseo_metakey() { |
| 288 |
return WPSEO_Meta::get_value( 'metakey', ph_get_page_id('search_results') ); |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
/** |
| 293 |
* Hook into the_posts to do the main property query if needed - relevanssi compatibility |
| 294 |
* |
| 295 |
* @access public |
| 296 |
* @param array $posts |
| 297 |
* @param WP_Query|bool $query (default: false) |
| 298 |
* @return array |
| 299 |
*/ |
| 300 |
public function the_posts( $posts, $query = false ) { |
| 301 |
|
| 302 |
// Abort if there's no query |
| 303 |
if ( ! $query ) |
| 304 |
return $posts; |
| 305 |
|
| 306 |
// Abort if we're not filtering posts |
| 307 |
if ( empty( $this->post__in ) ) |
| 308 |
return $posts; |
| 309 |
|
| 310 |
// Abort if this query has already been done |
| 311 |
if ( ! empty( $query->ph_query ) ) |
| 312 |
return $posts; |
| 313 |
|
| 314 |
// Abort if this isn't a search query |
| 315 |
if ( empty( $query->query_vars["s"] ) ) |
| 316 |
return $posts; |
| 317 |
|
| 318 |
// Abort if we're not on a post type archive/property taxonomy |
| 319 |
if ( ! $query->is_post_type_archive( 'property' ) && ! $query->is_tax( get_object_taxonomies( 'property' ) ) ) |
| 320 |
return $posts; |
| 321 |
|
| 322 |
$filtered_posts = array(); |
| 323 |
$queried_post_ids = array(); |
| 324 |
|
| 325 |
foreach ( $posts as $post ) { |
| 326 |
if ( in_array( $post->ID, $this->post__in ) ) { |
| 327 |
$filtered_posts[] = $post; |
| 328 |
$queried_post_ids[] = $post->ID; |
| 329 |
} |
| 330 |
} |
| 331 |
|
| 332 |
$query->posts = $filtered_posts; |
| 333 |
$query->post_count = count( $filtered_posts ); |
| 334 |
|
| 335 |
// Ensure filters are set |
| 336 |
$this->unfiltered_property_ids = $queried_post_ids; |
| 337 |
$this->filtered_property_ids = $queried_post_ids; |
| 338 |
|
| 339 |
if ( sizeof( $this->layered_nav_post__in ) > 0 ) { |
| 340 |
$this->layered_nav_property_ids = array_intersect( $this->unfiltered_property_ids, $this->layered_nav_post__in ); |
| 341 |
} else { |
| 342 |
$this->layered_nav_property_ids = $this->unfiltered_property_ids; |
| 343 |
} |
| 344 |
|
| 345 |
return $filtered_posts; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
/** |
| 350 |
* Query the properties, applying sorting/ordering etc. This applies to the main wordpress loop |
| 351 |
* |
| 352 |
* @access public |
| 353 |
* @param mixed $q |
| 354 |
* @return void |
| 355 |
*/ |
| 356 |
public function property_query( $q ) { |
| 357 |
|
| 358 |
// Meta query |
| 359 |
$meta_query = $this->get_meta_query( $q ); |
| 360 |
|
| 361 |
// Tax query |
| 362 |
$tax_query = $this->get_tax_query( $q->get( 'tax_query' ) ); |
| 363 |
|
| 364 |
// Date query |
| 365 |
$date_query = $this->get_date_query(); |
| 366 |
|
| 367 |
// Ordering |
| 368 |
$ordering = $this->get_search_results_ordering_args(); |
| 369 |
|
| 370 |
// Get a list of post id's which match the current filters set (in the layered nav and price filter) |
| 371 |
$post__in = array(); |
| 372 |
//$post__in = array_unique( apply_filters( 'loop_shop_post_in', array() ) ); |
| 373 |
|
| 374 |
// Ordering query vars |
| 375 |
$q->set( 'orderby', $ordering['orderby'] ); |
| 376 |
$q->set( 'order', $ordering['order'] ); |
| 377 |
if ( isset( $ordering['meta_key'] ) ) |
| 378 |
$q->set( 'meta_key', $ordering['meta_key'] ); |
| 379 |
|
| 380 |
// Query vars that affect posts shown |
| 381 |
$q->set( 'meta_query', $meta_query ); |
| 382 |
$q->set( 'tax_query', $tax_query ); |
| 383 |
$q->set( 'date_query', $date_query ); |
| 384 |
$q->set( 'post__in', $post__in ); |
| 385 |
$q->set( 'posts_per_page', $q->get( 'posts_per_page' ) ? $q->get( 'posts_per_page' ) : apply_filters( 'loop_search_results_per_page', get_option( 'posts_per_page' ) ) ); |
| 386 |
|
| 387 |
// Set a special variable |
| 388 |
$q->set( 'ph_query', true ); |
| 389 |
|
| 390 |
// Store variables |
| 391 |
$this->post__in = $post__in; |
| 392 |
$this->meta_query = $meta_query; |
| 393 |
$this->tax_query = $tax_query; |
| 394 |
|
| 395 |
do_action( 'propertyhive_property_query', $q, $this ); |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
/** |
| 400 |
* Remove the query |
| 401 |
* |
| 402 |
* @access public |
| 403 |
* @return void |
| 404 |
*/ |
| 405 |
public function remove_property_query() { |
| 406 |
remove_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ) ); |
| 407 |
} |
| 408 |
|
| 409 |
/** |
| 410 |
* Remove ordering queries |
| 411 |
*/ |
| 412 |
public function remove_ordering_args() { |
| 413 |
|
| 414 |
} |
| 415 |
|
| 416 |
/** |
| 417 |
* Remove the posts_where filter |
| 418 |
* |
| 419 |
* @access public |
| 420 |
* @return void |
| 421 |
*/ |
| 422 |
public function remove_posts_where() { |
| 423 |
remove_filter( 'posts_where', array( $this, 'search_post_excerpt' ) ); |
| 424 |
} |
| 425 |
|
| 426 |
|
| 427 |
/** |
| 428 |
* Get an unpaginated list all property ID's (both filtered and unfiltered). Makes use of transients. |
| 429 |
* |
| 430 |
* @access public |
| 431 |
* @return void |
| 432 |
*/ |
| 433 |
public function get_properties_in_view() { |
| 434 |
global $wp_the_query; |
| 435 |
|
| 436 |
$unfiltered_property_ids = array(); |
| 437 |
|
| 438 |
// Get main query |
| 439 |
$current_wp_query = $wp_the_query->query; |
| 440 |
|
| 441 |
// Get WP Query for current page (without 'paged') |
| 442 |
unset( $current_wp_query['paged'] ); |
| 443 |
|
| 444 |
// Generate a transient name based on current query |
| 445 |
$transient_name = 'ph_uf_pid_' . md5( http_build_query( $current_wp_query ) ); |
| 446 |
$transient_name = ( is_search() ) ? $transient_name . '_s' : $transient_name; |
| 447 |
|
| 448 |
if ( false === ( $unfiltered_property_ids = get_transient( $transient_name ) ) ) { |
| 449 |
|
| 450 |
// Get all visible posts, regardless of filters |
| 451 |
$unfiltered_property_ids = get_posts( |
| 452 |
array_merge( |
| 453 |
$current_wp_query, |
| 454 |
array( |
| 455 |
'post_type' => 'property', |
| 456 |
'numberposts' => -1, |
| 457 |
'post_status' => 'publish', |
| 458 |
'meta_query' => $this->meta_query, |
| 459 |
'fields' => 'ids', |
| 460 |
'no_found_rows' => true, |
| 461 |
'update_post_meta_cache' => false, |
| 462 |
'update_post_term_cache' => false |
| 463 |
) |
| 464 |
) |
| 465 |
); |
| 466 |
|
| 467 |
set_transient( $transient_name, $unfiltered_property_ids, YEAR_IN_SECONDS ); |
| 468 |
} |
| 469 |
|
| 470 |
// Store the variable |
| 471 |
$this->unfiltered_property_ids = $unfiltered_property_ids; |
| 472 |
|
| 473 |
// Also store filtered posts ids... |
| 474 |
if ( sizeof( $this->post__in ) > 0 ) |
| 475 |
$this->filtered_property_ids = array_intersect( $this->unfiltered_property_ids, $this->post__in ); |
| 476 |
else |
| 477 |
$this->filtered_property_ids = $this->unfiltered_property_ids; |
| 478 |
|
| 479 |
// And filtered post ids which just take layered nav into consideration (to find max price in the price widget) |
| 480 |
if ( sizeof( $this->layered_nav_post__in ) > 0 ) |
| 481 |
$this->layered_nav_property_ids = array_intersect( $this->unfiltered_property_ids, $this->layered_nav_post__in ); |
| 482 |
else |
| 483 |
$this->layered_nav_property_ids = $this->unfiltered_property_ids; |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
/** |
| 488 |
* Returns an array of arguments for ordering properties based on the selected values |
| 489 |
* |
| 490 |
* @access public |
| 491 |
* @return array |
| 492 |
*/ |
| 493 |
public function get_search_results_ordering_args( $orderby = '', $order = '' ) { |
| 494 |
// Get ordering from query string unless defined |
| 495 |
if ( ! $orderby ) { |
| 496 |
$orderby_value = isset( $_GET['orderby'] ) ? sanitize_text_field( $_GET['orderby'] ) : apply_filters( 'propertyhive_default_search_results_orderby', get_option( 'propertyhive_default_search_results_orderby' ) ); |
| 497 |
|
| 498 |
// Get order + orderby args from string |
| 499 |
$orderby_value = explode( '-', $orderby_value ); |
| 500 |
$orderby = esc_attr( $orderby_value[0] ); |
| 501 |
$order = ! empty( $orderby_value[1] ) ? $orderby_value[1] : $order; |
| 502 |
} |
| 503 |
|
| 504 |
$orderby = strtolower( $orderby ); |
| 505 |
$order = strtoupper( $order ); |
| 506 |
|
| 507 |
$args = array(); |
| 508 |
|
| 509 |
// default - menu_order |
| 510 |
if ( |
| 511 |
( isset($_REQUEST['department']) && $_REQUEST['department'] != 'commercial' ) || |
| 512 |
( !isset($_REQUEST['department']) && get_option( 'propertyhive_primary_department' ) != 'commercial' ) |
| 513 |
) |
| 514 |
{ |
| 515 |
$args['orderby'] = 'meta_value_num'; |
| 516 |
$args['order'] = $order == 'ASC' ? 'ASC' : 'DESC'; |
| 517 |
$args['meta_key'] = '_price_actual'; |
| 518 |
} |
| 519 |
elseif ( |
| 520 |
( isset($_REQUEST['department']) && $_REQUEST['department'] == 'commercial' ) || |
| 521 |
( !isset($_REQUEST['department']) && get_option( 'propertyhive_primary_department' ) == 'commercial' ) |
| 522 |
) |
| 523 |
{ |
| 524 |
$args['orderby'] = 'meta_value_num'; |
| 525 |
$args['order'] = $order == 'ASC' ? 'ASC' : 'DESC'; |
| 526 |
$args['meta_key'] = '_floor_area_from_sqft'; |
| 527 |
} |
| 528 |
|
| 529 |
switch ( $orderby ) { |
| 530 |
case 'price' : |
| 531 |
$args['orderby'] = 'meta_value_num'; |
| 532 |
$args['order'] = $order == 'ASC' ? 'ASC' : 'DESC'; |
| 533 |
if ( |
| 534 |
( isset($_REQUEST['department']) && $_REQUEST['department'] == 'commercial' ) || |
| 535 |
( !isset($_REQUEST['department']) && get_option( 'propertyhive_primary_department' ) == 'commercial' ) |
| 536 |
) |
| 537 |
{ |
| 538 |
$args['meta_key'] = '_price_from_actual'; |
| 539 |
} |
| 540 |
else |
| 541 |
{ |
| 542 |
$args['meta_key'] = '_price_actual'; |
| 543 |
} |
| 544 |
break; |
| 545 |
case 'floor_area' : |
| 546 |
$args['orderby'] = 'meta_value_num'; |
| 547 |
$args['order'] = $order == 'ASC' ? 'ASC' : 'DESC'; |
| 548 |
$args['meta_key'] = '_floor_area_from_sqft'; |
| 549 |
break; |
| 550 |
default : |
| 551 |
{ |
| 552 |
if ( $orderby != '' ) |
| 553 |
{ |
| 554 |
$args['orderby'] = $orderby; |
| 555 |
$args['order'] = $order == 'ASC' ? 'ASC' : 'DESC'; |
| 556 |
} |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
return apply_filters( 'propertyhive_get_search_results_ordering_args', $args ); |
| 561 |
} |
| 562 |
|
| 563 |
/** |
| 564 |
* Appends date queries to an array. |
| 565 |
* @access public |
| 566 |
* @param array $meta_query |
| 567 |
* @return array |
| 568 |
*/ |
| 569 |
public function get_date_query() { |
| 570 |
|
| 571 |
$date_query = array(); |
| 572 |
|
| 573 |
if ( isset( $_REQUEST['added_from'] ) && $_REQUEST['added_from'] != '' ) |
| 574 |
{ |
| 575 |
$date_query = array( |
| 576 |
'column' => 'post_date_gmt', |
| 577 |
'after' => sanitize_text_field( $_REQUEST['added_from'] ) |
| 578 |
); |
| 579 |
} |
| 580 |
|
| 581 |
if ( isset( $_REQUEST['added_from_hours'] ) && $_REQUEST['added_from_hours'] != '' ) |
| 582 |
{ |
| 583 |
$date_query = array( |
| 584 |
'column' => 'post_date_gmt', |
| 585 |
'after' => sanitize_text_field( $_REQUEST['added_from_hours'] ) . ' hours ago' |
| 586 |
); |
| 587 |
} |
| 588 |
|
| 589 |
return array_filter( $date_query ); |
| 590 |
} |
| 591 |
|
| 592 |
/** |
| 593 |
* Appends meta queries to an array. |
| 594 |
* @access public |
| 595 |
* @param array $meta_query |
| 596 |
* @return array |
| 597 |
*/ |
| 598 |
public function get_meta_query( $q = array() ) { |
| 599 |
|
| 600 |
$meta_query = array(); |
| 601 |
if ( !empty($q) ) |
| 602 |
{ |
| 603 |
$meta_query = $q->get( 'meta_query' ); |
| 604 |
} |
| 605 |
|
| 606 |
if ( ! is_array( $meta_query ) ) |
| 607 |
$meta_query = array(); |
| 608 |
|
| 609 |
$meta_query[] = $this->on_market_meta_query(); |
| 610 |
$meta_query[] = $this->department_meta_query($q); |
| 611 |
$meta_query[] = $this->address_keyword_meta_query(); |
| 612 |
$meta_query[] = $this->country_meta_query(); |
| 613 |
$meta_query[] = $this->minimum_price_meta_query(); |
| 614 |
$meta_query[] = $this->maximum_price_meta_query(); |
| 615 |
$meta_query[] = $this->price_range_meta_query(); |
| 616 |
$meta_query[] = $this->minimum_rent_meta_query(); |
| 617 |
$meta_query[] = $this->maximum_rent_meta_query(); |
| 618 |
$meta_query[] = $this->rent_range_meta_query(); |
| 619 |
$meta_query[] = $this->bedrooms_meta_query(); |
| 620 |
$meta_query[] = $this->minimum_bedrooms_meta_query(); |
| 621 |
$meta_query[] = $this->maximum_bedrooms_meta_query(); |
| 622 |
$meta_query[] = $this->minimum_bathrooms_meta_query(); |
| 623 |
$meta_query[] = $this->maximum_bathrooms_meta_query(); |
| 624 |
$meta_query[] = $this->minimum_reception_rooms_meta_query(); |
| 625 |
$meta_query[] = $this->maximum_reception_rooms_meta_query(); |
| 626 |
$meta_query[] = $this->available_date_from_meta_query(); |
| 627 |
$meta_query[] = $this->minimum_floor_area_meta_query(); |
| 628 |
$meta_query[] = $this->maximum_floor_area_meta_query(); |
| 629 |
$meta_query[] = $this->minimum_maximum_floor_area_meta_query(); |
| 630 |
$meta_query[] = $this->floor_area_range_meta_query(); |
| 631 |
$meta_query[] = $this->commercial_for_sale_to_rent_meta_query(); |
| 632 |
$meta_query[] = $this->commercial_for_sale_meta_query(); |
| 633 |
$meta_query[] = $this->commercial_to_rent_meta_query(); |
| 634 |
$meta_query[] = $this->negotiator_meta_query(); |
| 635 |
$meta_query[] = $this->office_meta_query(); |
| 636 |
|
| 637 |
return array_filter( apply_filters( 'propertyhive_property_query_meta_query', $meta_query, $this ) ); |
| 638 |
} |
| 639 |
|
| 640 |
/** |
| 641 |
* Returns a meta query to handle property on market status |
| 642 |
* |
| 643 |
* @access public |
| 644 |
* @param string $compare (default: 'IN') |
| 645 |
* @return array |
| 646 |
*/ |
| 647 |
public function on_market_meta_query( ) { |
| 648 |
|
| 649 |
$meta_query = array(); |
| 650 |
|
| 651 |
if ( !is_admin() ) |
| 652 |
{ |
| 653 |
$meta_query = array( |
| 654 |
'key' => '_on_market', |
| 655 |
'value' => 'yes', |
| 656 |
'compare' => '=' |
| 657 |
); |
| 658 |
} |
| 659 |
|
| 660 |
return $meta_query; |
| 661 |
} |
| 662 |
|
| 663 |
/** |
| 664 |
* Returns a meta query to handle property department |
| 665 |
* |
| 666 |
* @access public |
| 667 |
* @return array |
| 668 |
*/ |
| 669 |
public function department_meta_query( $q ) { |
| 670 |
|
| 671 |
$meta_query = array(); |
| 672 |
|
| 673 |
if ( isset( $_REQUEST['department'] ) && $_REQUEST['department'] != '' ) |
| 674 |
{ |
| 675 |
$meta_query = array( |
| 676 |
'key' => '_department', |
| 677 |
'value' => sanitize_text_field( $_REQUEST['department'] ), |
| 678 |
'compare' => '=' |
| 679 |
); |
| 680 |
} |
| 681 |
else |
| 682 |
{ |
| 683 |
// Need a department set if on search results page |
| 684 |
if (!empty($q) && $q->is_post_type_archive( 'property' )) |
| 685 |
{ |
| 686 |
if (get_option( 'propertyhive_primary_department' ) != '') |
| 687 |
{ |
| 688 |
$department = get_option( 'propertyhive_primary_department' ); |
| 689 |
} |
| 690 |
else |
| 691 |
{ |
| 692 |
// No primary department set. Use first active one. Should never get to this scenario |
| 693 |
$department = ''; |
| 694 |
|
| 695 |
$departments = ph_get_departments(); |
| 696 |
|
| 697 |
foreach ( $departments as $key => $value ) |
| 698 |
{ |
| 699 |
if ( get_option( 'propertyhive_active_departments_' . str_replace("residential-", "", $key) ) == 'yes' ) |
| 700 |
{ |
| 701 |
if ( $department == '' ) |
| 702 |
{ |
| 703 |
$department = $key; |
| 704 |
} |
| 705 |
} |
| 706 |
} |
| 707 |
} |
| 708 |
$meta_query = array( |
| 709 |
'key' => '_department', |
| 710 |
'value' => $department, |
| 711 |
'compare' => '=' |
| 712 |
); |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
return $meta_query; |
| 717 |
} |
| 718 |
|
| 719 |
/** |
| 720 |
* Returns a meta query to handle searching for a keyword in the address |
| 721 |
* |
| 722 |
* @access public |
| 723 |
* @param string $compare (default: 'IN') |
| 724 |
* @return array |
| 725 |
*/ |
| 726 |
public function address_keyword_meta_query( ) { |
| 727 |
|
| 728 |
$meta_query = array(); |
| 729 |
|
| 730 |
if ( isset( $_REQUEST['address_keyword'] ) && $_REQUEST['address_keyword'] != '' ) |
| 731 |
{ |
| 732 |
$_REQUEST['address_keyword'] = ph_clean( wp_unslash( $_REQUEST['address_keyword'] ) ); |
| 733 |
|
| 734 |
// Remove country code from end (i.e. ', UK') |
| 735 |
$_REQUEST['address_keyword'] = preg_replace('/\,\s?[A-Z][A-Z]$/', '', $_REQUEST['address_keyword']); |
| 736 |
|
| 737 |
$address_keywords = array( $_REQUEST['address_keyword'] ); |
| 738 |
|
| 739 |
if ( strpos( $_REQUEST['address_keyword'], ' ' ) !== FALSE ) |
| 740 |
{ |
| 741 |
$address_keywords[] = str_replace(" ", "-", ph_clean($_REQUEST['address_keyword'])); |
| 742 |
} |
| 743 |
if ( strpos( $_REQUEST['address_keyword'], '-' ) !== FALSE ) |
| 744 |
{ |
| 745 |
$address_keywords[] = str_replace("-", " ", ph_clean($_REQUEST['address_keyword'])); |
| 746 |
} |
| 747 |
|
| 748 |
$meta_query = array('relation' => 'OR'); |
| 749 |
|
| 750 |
$address_fields_to_query = array( |
| 751 |
'_reference_number', |
| 752 |
'_address_street', |
| 753 |
'_address_two', |
| 754 |
'_address_three', |
| 755 |
'_address_four', |
| 756 |
'_address_postcode' |
| 757 |
); |
| 758 |
|
| 759 |
$address_fields_to_query = apply_filters( 'propertyhive_address_fields_to_query', $address_fields_to_query ); |
| 760 |
|
| 761 |
foreach ( $address_keywords as $address_keyword ) |
| 762 |
{ |
| 763 |
foreach ( $address_fields_to_query as $address_field ) |
| 764 |
{ |
| 765 |
if ( $address_field == '_address_postcode' ) { continue; } // ignore postcode as that is handled differently afterwards |
| 766 |
|
| 767 |
$meta_query[] = array( |
| 768 |
'key' => $address_field, |
| 769 |
'value' => $address_keyword, |
| 770 |
'compare' => get_option( 'propertyhive_address_keyword_compare', '=' ) |
| 771 |
); |
| 772 |
} |
| 773 |
} |
| 774 |
if ( in_array('_address_postcode', $address_fields_to_query) ) |
| 775 |
{ |
| 776 |
if ( strlen($_REQUEST['address_keyword']) <= 4 ) |
| 777 |
{ |
| 778 |
$meta_query[] = array( |
| 779 |
'key' => '_address_postcode', |
| 780 |
'value' => ph_clean( $_REQUEST['address_keyword'] ), |
| 781 |
'compare' => '=' |
| 782 |
); |
| 783 |
$meta_query[] = array( |
| 784 |
'key' => '_address_postcode', |
| 785 |
'value' => '^' . ph_clean( $_REQUEST['address_keyword'] ) . '[ ]', |
| 786 |
'compare' => 'RLIKE' |
| 787 |
); |
| 788 |
} |
| 789 |
else |
| 790 |
{ |
| 791 |
$postcode = ph_clean( $_REQUEST['address_keyword'] ); |
| 792 |
|
| 793 |
if ( preg_match('#^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW])[0-9][ABD-HJLNP-UW-Z]{2})$#i', $postcode) ) |
| 794 |
{ |
| 795 |
// UK postcode found with no space |
| 796 |
|
| 797 |
if ( strlen($postcode) == 5 ) |
| 798 |
{ |
| 799 |
$first_part = substr($postcode, 0, 2); |
| 800 |
$last_part = substr($postcode, 2, 3); |
| 801 |
|
| 802 |
$postcode = $first_part . ' ' . $last_part; |
| 803 |
} |
| 804 |
elseif ( strlen($postcode) == 6 ) |
| 805 |
{ |
| 806 |
$first_part = substr($postcode, 0, 3); |
| 807 |
$last_part = substr($postcode, 3, 3); |
| 808 |
|
| 809 |
$postcode = $first_part . ' ' . $last_part; |
| 810 |
} |
| 811 |
elseif ( strlen($postcode) == 7 ) |
| 812 |
{ |
| 813 |
$first_part = substr($postcode, 0, 4); |
| 814 |
$last_part = substr($postcode, 4, 3); |
| 815 |
|
| 816 |
$postcode = $first_part . ' ' . $last_part; |
| 817 |
} |
| 818 |
} |
| 819 |
|
| 820 |
$meta_query[] = array( |
| 821 |
'key' => '_address_postcode', |
| 822 |
'value' => ph_clean( $postcode ), |
| 823 |
'compare' => 'LIKE' |
| 824 |
); |
| 825 |
} |
| 826 |
} |
| 827 |
} |
| 828 |
|
| 829 |
return $meta_query; |
| 830 |
} |
| 831 |
|
| 832 |
/** |
| 833 |
* Returns a meta query to handle country |
| 834 |
* |
| 835 |
* @access public |
| 836 |
* @return array |
| 837 |
*/ |
| 838 |
public function country_meta_query( ) { |
| 839 |
|
| 840 |
$meta_query = array(); |
| 841 |
|
| 842 |
if ( isset( $_REQUEST['country'] ) && $_REQUEST['country'] != '' ) |
| 843 |
{ |
| 844 |
$meta_query = array( |
| 845 |
'key' => '_address_country', |
| 846 |
'value' => ph_clean( $_REQUEST['country'] ) |
| 847 |
); |
| 848 |
} |
| 849 |
|
| 850 |
return $meta_query; |
| 851 |
} |
| 852 |
|
| 853 |
/** |
| 854 |
* Returns a meta query to handle minimum price |
| 855 |
* |
| 856 |
* @access public |
| 857 |
* @return array |
| 858 |
*/ |
| 859 |
public function minimum_price_meta_query( ) { |
| 860 |
|
| 861 |
$meta_query = array(); |
| 862 |
|
| 863 |
if ( |
| 864 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales' && |
| 865 |
isset( $_REQUEST['minimum_price'] ) && $_REQUEST['minimum_price'] != '' |
| 866 |
) |
| 867 |
{ |
| 868 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 869 |
|
| 870 |
$minimum_price = $_REQUEST['minimum_price']; |
| 871 |
if ( $search_form_currency != 'GBP' ) |
| 872 |
{ |
| 873 |
// Convert $_REQUEST['minimum_price'] to GBP |
| 874 |
$ph_countries = new PH_Countries(); |
| 875 |
|
| 876 |
$minimum_price = $ph_countries->convert_price_to_gbp( $minimum_price, $search_form_currency ); |
| 877 |
} |
| 878 |
|
| 879 |
$meta_query = array( |
| 880 |
'key' => '_price_actual', |
| 881 |
'value' => ph_clean( floor( $minimum_price ) ), |
| 882 |
'compare' => '>=', |
| 883 |
'type' => 'NUMERIC' |
| 884 |
); |
| 885 |
} |
| 886 |
|
| 887 |
return $meta_query; |
| 888 |
} |
| 889 |
|
| 890 |
/** |
| 891 |
* Returns a meta query to handle maximum price |
| 892 |
* |
| 893 |
* @access public |
| 894 |
* @return array |
| 895 |
*/ |
| 896 |
public function maximum_price_meta_query( ) { |
| 897 |
|
| 898 |
$meta_query = array(); |
| 899 |
|
| 900 |
if ( |
| 901 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales' && |
| 902 |
isset( $_REQUEST['maximum_price'] ) && $_REQUEST['maximum_price'] != '' |
| 903 |
) |
| 904 |
{ |
| 905 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 906 |
|
| 907 |
$maximum_price = $_REQUEST['maximum_price']; |
| 908 |
if ( $search_form_currency != 'GBP' ) |
| 909 |
{ |
| 910 |
// Convert $_REQUEST['maximum_price'] to GBP |
| 911 |
$ph_countries = new PH_Countries(); |
| 912 |
|
| 913 |
$maximum_price = $ph_countries->convert_price_to_gbp( $maximum_price, $search_form_currency ); |
| 914 |
} |
| 915 |
|
| 916 |
$meta_query = array( |
| 917 |
'key' => '_price_actual', |
| 918 |
'value' => ph_clean( ceil( $maximum_price ) ), |
| 919 |
'compare' => '<=', |
| 920 |
'type' => 'NUMERIC' |
| 921 |
); |
| 922 |
} |
| 923 |
|
| 924 |
return $meta_query; |
| 925 |
} |
| 926 |
|
| 927 |
/** |
| 928 |
* Returns a meta query to handle price range |
| 929 |
* |
| 930 |
* @access public |
| 931 |
* @return array |
| 932 |
*/ |
| 933 |
public function price_range_meta_query( ) { |
| 934 |
|
| 935 |
$meta_query = array(); |
| 936 |
|
| 937 |
if ( |
| 938 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales' && |
| 939 |
isset( $_REQUEST['price_range'] ) && $_REQUEST['price_range'] != '' |
| 940 |
) |
| 941 |
{ |
| 942 |
$explode_price_range = explode("-", ph_clean($_REQUEST['price_range'])); |
| 943 |
|
| 944 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 945 |
|
| 946 |
if ( isset($explode_price_range[0]) && $explode_price_range[0] != '' ) |
| 947 |
{ |
| 948 |
$minimum_price = $explode_price_range[0]; |
| 949 |
|
| 950 |
if ( $search_form_currency != 'GBP' ) |
| 951 |
{ |
| 952 |
// Convert $explode_price_range[0] to GBP |
| 953 |
$ph_countries = new PH_Countries(); |
| 954 |
|
| 955 |
$minimum_price = $ph_countries->convert_price_to_gbp( $minimum_price, $search_form_currency ); |
| 956 |
} |
| 957 |
|
| 958 |
$meta_query[] = array( |
| 959 |
'key' => '_price_actual', |
| 960 |
'value' => sanitize_text_field( floor( $minimum_price ) ), |
| 961 |
'compare' => '>=', |
| 962 |
'type' => 'NUMERIC' |
| 963 |
); |
| 964 |
} |
| 965 |
if ( isset($explode_price_range[1]) && $explode_price_range[1] != '' ) |
| 966 |
{ |
| 967 |
$maximum_price = $explode_price_range[1]; |
| 968 |
if ( $search_form_currency != 'GBP' ) |
| 969 |
{ |
| 970 |
// Convert $explode_price_range[1] to GBP |
| 971 |
$ph_countries = new PH_Countries(); |
| 972 |
|
| 973 |
$maximum_price = $ph_countries->convert_price_to_gbp( $maximum_price, $search_form_currency ); |
| 974 |
} |
| 975 |
|
| 976 |
$meta_query[] = array( |
| 977 |
'key' => '_price_actual', |
| 978 |
'value' => sanitize_text_field( ceil( $maximum_price ) ), |
| 979 |
'compare' => '<=', |
| 980 |
'type' => 'NUMERIC' |
| 981 |
); |
| 982 |
} |
| 983 |
} |
| 984 |
|
| 985 |
return $meta_query; |
| 986 |
} |
| 987 |
|
| 988 |
/** |
| 989 |
* Returns a meta query to handle minimum rent |
| 990 |
* |
| 991 |
* @access public |
| 992 |
* @return array |
| 993 |
*/ |
| 994 |
public function minimum_rent_meta_query( ) { |
| 995 |
|
| 996 |
$meta_query = array(); |
| 997 |
|
| 998 |
if ( |
| 999 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings' && |
| 1000 |
isset( $_REQUEST['minimum_rent'] ) && $_REQUEST['minimum_rent'] != '' |
| 1001 |
) |
| 1002 |
{ |
| 1003 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 1004 |
|
| 1005 |
$minimum_rent = $_REQUEST['minimum_rent']; |
| 1006 |
if ( $search_form_currency != 'GBP' ) |
| 1007 |
{ |
| 1008 |
// Convert $_REQUEST['minimum_rent'] to GBP |
| 1009 |
$ph_countries = new PH_Countries(); |
| 1010 |
|
| 1011 |
$minimum_rent = $ph_countries->convert_price_to_gbp( $minimum_rent, $search_form_currency ); |
| 1012 |
} |
| 1013 |
|
| 1014 |
$meta_query = array( |
| 1015 |
'key' => '_price_actual', |
| 1016 |
'value' => ph_clean( floor( $minimum_rent ) ), |
| 1017 |
'compare' => '>=', |
| 1018 |
'type' => 'NUMERIC' |
| 1019 |
); |
| 1020 |
} |
| 1021 |
|
| 1022 |
return $meta_query; |
| 1023 |
} |
| 1024 |
|
| 1025 |
/** |
| 1026 |
* Returns a meta query to handle maximum rent |
| 1027 |
* |
| 1028 |
* @access public |
| 1029 |
* @return array |
| 1030 |
*/ |
| 1031 |
public function maximum_rent_meta_query( ) { |
| 1032 |
|
| 1033 |
$meta_query = array(); |
| 1034 |
|
| 1035 |
if ( |
| 1036 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings' && |
| 1037 |
isset( $_REQUEST['maximum_rent'] ) && $_REQUEST['maximum_rent'] != '' |
| 1038 |
) |
| 1039 |
{ |
| 1040 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 1041 |
|
| 1042 |
$maximum_rent = $_REQUEST['maximum_rent']; |
| 1043 |
if ( $search_form_currency != 'GBP' ) |
| 1044 |
{ |
| 1045 |
// Convert $_REQUEST['maximum_rent'] to GBP |
| 1046 |
$ph_countries = new PH_Countries(); |
| 1047 |
|
| 1048 |
$maximum_rent = $ph_countries->convert_price_to_gbp( $maximum_rent, $search_form_currency ); |
| 1049 |
} |
| 1050 |
|
| 1051 |
$meta_query = array( |
| 1052 |
'key' => '_price_actual', |
| 1053 |
'value' => ph_clean( ceil( $maximum_rent ) ), |
| 1054 |
'compare' => '<=', |
| 1055 |
'type' => 'NUMERIC' |
| 1056 |
); |
| 1057 |
} |
| 1058 |
|
| 1059 |
return $meta_query; |
| 1060 |
} |
| 1061 |
|
| 1062 |
/** |
| 1063 |
* Returns a meta query to handle rent range |
| 1064 |
* |
| 1065 |
* @access public |
| 1066 |
* @return array |
| 1067 |
*/ |
| 1068 |
public function rent_range_meta_query( ) { |
| 1069 |
|
| 1070 |
$meta_query = array(); |
| 1071 |
|
| 1072 |
if ( |
| 1073 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings' && |
| 1074 |
isset( $_REQUEST['rent_range'] ) && $_REQUEST['rent_range'] != '' |
| 1075 |
) |
| 1076 |
{ |
| 1077 |
$explode_rent_range = explode("-", ph_clean($_REQUEST['rent_range'])); |
| 1078 |
|
| 1079 |
$search_form_currency = get_option( 'propertyhive_search_form_currency', 'GBP' ); |
| 1080 |
|
| 1081 |
if ( isset($explode_rent_range[0]) && $explode_rent_range[0] != '' ) |
| 1082 |
{ |
| 1083 |
$minimum_rent = $explode_rent_range[0]; |
| 1084 |
if ( $search_form_currency != 'GBP' ) |
| 1085 |
{ |
| 1086 |
// Convert $explode_rent_range[0] to GBP |
| 1087 |
$ph_countries = new PH_Countries(); |
| 1088 |
|
| 1089 |
$minimum_rent = $ph_countries->convert_price_to_gbp( $minimum_rent, $search_form_currency ); |
| 1090 |
} |
| 1091 |
|
| 1092 |
$meta_query[] = array( |
| 1093 |
'key' => '_price_actual', |
| 1094 |
'value' => sanitize_text_field( floor( $minimum_rent ) ), |
| 1095 |
'compare' => '>=', |
| 1096 |
'type' => 'NUMERIC' |
| 1097 |
); |
| 1098 |
} |
| 1099 |
if ( isset($explode_rent_range[1]) && $explode_rent_range[1] != '' ) |
| 1100 |
{ |
| 1101 |
$maximum_rent = $explode_rent_range[1]; |
| 1102 |
if ( $search_form_currency != 'GBP' ) |
| 1103 |
{ |
| 1104 |
// Convert $explode_rent_range[1] to GBP |
| 1105 |
$ph_countries = new PH_Countries(); |
| 1106 |
|
| 1107 |
$maximum_rent = $ph_countries->convert_price_to_gbp( $maximum_rent, $search_form_currency ); |
| 1108 |
} |
| 1109 |
|
| 1110 |
$meta_query[] = array( |
| 1111 |
'key' => '_price_actual', |
| 1112 |
'value' => sanitize_text_field( ceil( $maximum_rent ) ), |
| 1113 |
'compare' => '<=', |
| 1114 |
'type' => 'NUMERIC' |
| 1115 |
); |
| 1116 |
} |
| 1117 |
} |
| 1118 |
|
| 1119 |
return $meta_query; |
| 1120 |
} |
| 1121 |
|
| 1122 |
/** |
| 1123 |
* Returns a meta query to handle exact bedrooms |
| 1124 |
* |
| 1125 |
* @access public |
| 1126 |
* @return array |
| 1127 |
*/ |
| 1128 |
public function bedrooms_meta_query( ) { |
| 1129 |
|
| 1130 |
$meta_query = array(); |
| 1131 |
|
| 1132 |
if ( |
| 1133 |
( |
| 1134 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1135 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1136 |
) && |
| 1137 |
isset( $_REQUEST['bedrooms'] ) && $_REQUEST['bedrooms'] != '' |
| 1138 |
) |
| 1139 |
{ |
| 1140 |
$meta_query = array( |
| 1141 |
'key' => '_bedrooms', |
| 1142 |
'value' => ph_clean( $_REQUEST['bedrooms'] ), |
| 1143 |
'compare' => '=', |
| 1144 |
'type' => 'NUMERIC' |
| 1145 |
); |
| 1146 |
} |
| 1147 |
|
| 1148 |
return $meta_query; |
| 1149 |
} |
| 1150 |
|
| 1151 |
/** |
| 1152 |
* Returns a meta query to handle minimum bedrooms |
| 1153 |
* |
| 1154 |
* @access public |
| 1155 |
* @return array |
| 1156 |
*/ |
| 1157 |
public function minimum_bedrooms_meta_query( ) { |
| 1158 |
|
| 1159 |
$meta_query = array(); |
| 1160 |
|
| 1161 |
if ( |
| 1162 |
( |
| 1163 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1164 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1165 |
) && |
| 1166 |
isset( $_REQUEST['minimum_bedrooms'] ) && $_REQUEST['minimum_bedrooms'] != '' |
| 1167 |
) |
| 1168 |
{ |
| 1169 |
$meta_query = array( |
| 1170 |
'key' => '_bedrooms', |
| 1171 |
'value' => ph_clean( $_REQUEST['minimum_bedrooms'] ), |
| 1172 |
'compare' => '>=', |
| 1173 |
'type' => 'NUMERIC' |
| 1174 |
); |
| 1175 |
} |
| 1176 |
|
| 1177 |
return $meta_query; |
| 1178 |
} |
| 1179 |
|
| 1180 |
/** |
| 1181 |
* Returns a meta query to handle maximum bedrooms |
| 1182 |
* |
| 1183 |
* @access public |
| 1184 |
* @return array |
| 1185 |
*/ |
| 1186 |
public function maximum_bedrooms_meta_query( ) { |
| 1187 |
|
| 1188 |
$meta_query = array(); |
| 1189 |
|
| 1190 |
if ( |
| 1191 |
( |
| 1192 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1193 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1194 |
) && |
| 1195 |
isset( $_REQUEST['maximum_bedrooms'] ) && $_REQUEST['maximum_bedrooms'] != '' |
| 1196 |
) |
| 1197 |
{ |
| 1198 |
$meta_query = array( |
| 1199 |
'key' => '_bedrooms', |
| 1200 |
'value' => ph_clean( $_REQUEST['maximum_bedrooms'] ), |
| 1201 |
'compare' => '<=', |
| 1202 |
'type' => 'NUMERIC' |
| 1203 |
); |
| 1204 |
} |
| 1205 |
|
| 1206 |
return $meta_query; |
| 1207 |
} |
| 1208 |
|
| 1209 |
/** |
| 1210 |
* Returns a meta query to handle minimum bathrooms |
| 1211 |
* |
| 1212 |
* @access public |
| 1213 |
* @return array |
| 1214 |
*/ |
| 1215 |
public function minimum_bathrooms_meta_query( ) { |
| 1216 |
|
| 1217 |
$meta_query = array(); |
| 1218 |
|
| 1219 |
if ( |
| 1220 |
( |
| 1221 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1222 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1223 |
) && |
| 1224 |
isset( $_REQUEST['minimum_bathrooms'] ) && $_REQUEST['minimum_bathrooms'] != '' |
| 1225 |
) |
| 1226 |
{ |
| 1227 |
$meta_query = array( |
| 1228 |
'key' => '_bathrooms', |
| 1229 |
'value' => ph_clean( $_REQUEST['minimum_bathrooms'] ), |
| 1230 |
'compare' => '>=', |
| 1231 |
'type' => 'NUMERIC' |
| 1232 |
); |
| 1233 |
} |
| 1234 |
|
| 1235 |
return $meta_query; |
| 1236 |
} |
| 1237 |
|
| 1238 |
/** |
| 1239 |
* Returns a meta query to handle maximum bathrooms |
| 1240 |
* |
| 1241 |
* @access public |
| 1242 |
* @return array |
| 1243 |
*/ |
| 1244 |
public function maximum_bathrooms_meta_query( ) { |
| 1245 |
|
| 1246 |
$meta_query = array(); |
| 1247 |
|
| 1248 |
if ( |
| 1249 |
( |
| 1250 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1251 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1252 |
) && |
| 1253 |
isset( $_REQUEST['maximum_bathrooms'] ) && $_REQUEST['maximum_bathrooms'] != '' |
| 1254 |
) |
| 1255 |
{ |
| 1256 |
$meta_query = array( |
| 1257 |
'key' => '_bathrooms', |
| 1258 |
'value' => ph_clean( $_REQUEST['maximum_bathrooms'] ), |
| 1259 |
'compare' => '<=', |
| 1260 |
'type' => 'NUMERIC' |
| 1261 |
); |
| 1262 |
} |
| 1263 |
|
| 1264 |
return $meta_query; |
| 1265 |
} |
| 1266 |
|
| 1267 |
/** |
| 1268 |
* Returns a meta query to handle minimum reception rooms |
| 1269 |
* |
| 1270 |
* @access public |
| 1271 |
* @return array |
| 1272 |
*/ |
| 1273 |
public function minimum_reception_rooms_meta_query( ) { |
| 1274 |
|
| 1275 |
$meta_query = array(); |
| 1276 |
|
| 1277 |
if ( |
| 1278 |
( |
| 1279 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1280 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1281 |
) && |
| 1282 |
isset( $_REQUEST['minimum_reception_rooms'] ) && $_REQUEST['minimum_reception_rooms'] != '' |
| 1283 |
) |
| 1284 |
{ |
| 1285 |
$meta_query = array( |
| 1286 |
'key' => '_reception_rooms', |
| 1287 |
'value' => ph_clean( $_REQUEST['minimum_reception_rooms'] ), |
| 1288 |
'compare' => '>=', |
| 1289 |
'type' => 'NUMERIC' |
| 1290 |
); |
| 1291 |
} |
| 1292 |
|
| 1293 |
return $meta_query; |
| 1294 |
} |
| 1295 |
|
| 1296 |
/** |
| 1297 |
* Returns a meta query to handle maximum reception rooms |
| 1298 |
* |
| 1299 |
* @access public |
| 1300 |
* @return array |
| 1301 |
*/ |
| 1302 |
public function maximum_reception_rooms_meta_query( ) { |
| 1303 |
|
| 1304 |
$meta_query = array(); |
| 1305 |
|
| 1306 |
if ( |
| 1307 |
( |
| 1308 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-sales') || |
| 1309 |
(isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings') |
| 1310 |
) && |
| 1311 |
isset( $_REQUEST['maximum_reception_rooms'] ) && $_REQUEST['maximum_reception_rooms'] != '' |
| 1312 |
) |
| 1313 |
{ |
| 1314 |
$meta_query = array( |
| 1315 |
'key' => '_reception_rooms', |
| 1316 |
'value' => ph_clean( $_REQUEST['maximum_reception_rooms'] ), |
| 1317 |
'compare' => '<=', |
| 1318 |
'type' => 'NUMERIC' |
| 1319 |
); |
| 1320 |
} |
| 1321 |
|
| 1322 |
return $meta_query; |
| 1323 |
} |
| 1324 |
|
| 1325 |
/** |
| 1326 |
* Returns a meta query to handle available date from |
| 1327 |
* |
| 1328 |
* @access public |
| 1329 |
* @return array |
| 1330 |
*/ |
| 1331 |
public function available_date_from_meta_query( ) { |
| 1332 |
|
| 1333 |
$meta_query = array(); |
| 1334 |
|
| 1335 |
if ( |
| 1336 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'residential-lettings' && |
| 1337 |
isset( $_REQUEST['available_date_from'] ) && $_REQUEST['available_date_from'] != '' |
| 1338 |
) |
| 1339 |
{ |
| 1340 |
$available_date = ph_clean($_REQUEST['available_date_from']); |
| 1341 |
if ( strpos($available_date, '/') !== FALSE ) |
| 1342 |
{ |
| 1343 |
// it's been provided in the format dd/mm/yyyy |
| 1344 |
$explode_available_date = explode("/", $available_date); |
| 1345 |
if ( count($explode_available_date) == 3 ) |
| 1346 |
{ |
| 1347 |
$available_date = $explode_available_date[0] . '-' . $explode_available_date[1] . '-' . $explode_available_date[2]; |
| 1348 |
} |
| 1349 |
} |
| 1350 |
$meta_query = array( |
| 1351 |
'key' => '_available_date', |
| 1352 |
'value' => ph_clean( $available_date ), |
| 1353 |
'compare' => '<=', |
| 1354 |
); |
| 1355 |
} |
| 1356 |
|
| 1357 |
return $meta_query; |
| 1358 |
} |
| 1359 |
|
| 1360 |
/** |
| 1361 |
* Returns a meta query to handle minimum floor area |
| 1362 |
* |
| 1363 |
* @access public |
| 1364 |
* @return array |
| 1365 |
*/ |
| 1366 |
public function minimum_floor_area_meta_query( ) { |
| 1367 |
|
| 1368 |
$meta_query = array(); |
| 1369 |
|
| 1370 |
if ( |
| 1371 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1372 |
isset( $_REQUEST['minimum_floor_area'] ) && $_REQUEST['minimum_floor_area'] != '' && |
| 1373 |
( |
| 1374 |
!isset( $_REQUEST['maximum_floor_area'] ) || |
| 1375 |
( isset( $_REQUEST['maximum_floor_area'] ) && $_REQUEST['maximum_floor_area'] == '' ) |
| 1376 |
) |
| 1377 |
) |
| 1378 |
{ |
| 1379 |
$meta_query = array( |
| 1380 |
'key' => '_floor_area_from_sqft', |
| 1381 |
'value' => ph_clean( $_REQUEST['minimum_floor_area'] ), |
| 1382 |
'compare' => '>=', |
| 1383 |
'type' => 'NUMERIC' |
| 1384 |
); |
| 1385 |
} |
| 1386 |
|
| 1387 |
return $meta_query; |
| 1388 |
} |
| 1389 |
|
| 1390 |
/** |
| 1391 |
* Returns a meta query to handle maximum floor area |
| 1392 |
* |
| 1393 |
* @access public |
| 1394 |
* @return array |
| 1395 |
*/ |
| 1396 |
public function maximum_floor_area_meta_query( ) { |
| 1397 |
|
| 1398 |
$meta_query = array(); |
| 1399 |
|
| 1400 |
if ( |
| 1401 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1402 |
isset( $_REQUEST['maximum_floor_area'] ) && $_REQUEST['maximum_floor_area'] != '' && |
| 1403 |
( |
| 1404 |
!isset( $_REQUEST['minimum_floor_area'] ) || |
| 1405 |
( isset( $_REQUEST['minimum_floor_area'] ) && $_REQUEST['minimum_floor_area'] == '' ) |
| 1406 |
) |
| 1407 |
) |
| 1408 |
{ |
| 1409 |
$meta_query = array( |
| 1410 |
'key' => '_floor_area_to_sqft', |
| 1411 |
'value' => ph_clean( $_REQUEST['maximum_floor_area'] ), |
| 1412 |
'compare' => '<=', |
| 1413 |
'type' => 'NUMERIC' |
| 1414 |
); |
| 1415 |
} |
| 1416 |
|
| 1417 |
return $meta_query; |
| 1418 |
} |
| 1419 |
|
| 1420 |
/** |
| 1421 |
* Returns a meta query to handle minimum AND maximum floor area |
| 1422 |
* |
| 1423 |
* @access public |
| 1424 |
* @return array |
| 1425 |
*/ |
| 1426 |
public function minimum_maximum_floor_area_meta_query( ) { |
| 1427 |
|
| 1428 |
$meta_query = array(); |
| 1429 |
|
| 1430 |
if ( |
| 1431 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1432 |
isset( $_REQUEST['minimum_floor_area'] ) && $_REQUEST['minimum_floor_area'] != '' && |
| 1433 |
isset( $_REQUEST['maximum_floor_area'] ) && $_REQUEST['maximum_floor_area'] != '' |
| 1434 |
) |
| 1435 |
{ |
| 1436 |
$meta_query[] = array( |
| 1437 |
'key' => '_floor_area_from_sqft', |
| 1438 |
'value' => ph_clean( $_REQUEST['maximum_floor_area'] ), |
| 1439 |
'compare' => '<=', |
| 1440 |
'type' => 'NUMERIC' |
| 1441 |
); |
| 1442 |
$meta_query[] = array( |
| 1443 |
'key' => '_floor_area_to_sqft', |
| 1444 |
'value' => ph_clean( $_REQUEST['minimum_floor_area'] ), |
| 1445 |
'compare' => '>=', |
| 1446 |
'type' => 'NUMERIC' |
| 1447 |
); |
| 1448 |
} |
| 1449 |
|
| 1450 |
return $meta_query; |
| 1451 |
} |
| 1452 |
|
| 1453 |
|
| 1454 |
/** |
| 1455 |
* Returns a meta query to handle floor area range |
| 1456 |
* |
| 1457 |
* @access public |
| 1458 |
* @return array |
| 1459 |
*/ |
| 1460 |
public function floor_area_range_meta_query( ) { |
| 1461 |
|
| 1462 |
$meta_query = array(); |
| 1463 |
|
| 1464 |
if ( |
| 1465 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1466 |
isset( $_REQUEST['floor_area_range'] ) && $_REQUEST['floor_area_range'] != '' |
| 1467 |
) |
| 1468 |
{ |
| 1469 |
$explode_floor_area_range = explode("-", ph_clean($_REQUEST['floor_area_range'])); |
| 1470 |
|
| 1471 |
if ( isset($explode_floor_area_range[0]) && $explode_floor_area_range[0] != '' ) |
| 1472 |
{ |
| 1473 |
$meta_query = array( |
| 1474 |
'key' => '_floor_area_from_sqft', |
| 1475 |
'value' => ph_clean( $explode_floor_area_range[0] ), |
| 1476 |
'compare' => '>=', |
| 1477 |
'type' => 'NUMERIC' |
| 1478 |
); |
| 1479 |
} |
| 1480 |
if ( isset($explode_floor_area_range[1]) && $explode_floor_area_range[1] != '' ) |
| 1481 |
{ |
| 1482 |
$meta_query = array( |
| 1483 |
'key' => '_floor_area_to_sqft', |
| 1484 |
'value' => ph_clean( $explode_floor_area_range[1] ), |
| 1485 |
'compare' => '<=', |
| 1486 |
'type' => 'NUMERIC' |
| 1487 |
); |
| 1488 |
} |
| 1489 |
} |
| 1490 |
|
| 1491 |
return $meta_query; |
| 1492 |
} |
| 1493 |
|
| 1494 |
/** |
| 1495 |
* Returns a meta query to handle commercial for sale or to rent |
| 1496 |
* |
| 1497 |
* @access public |
| 1498 |
* @return array |
| 1499 |
*/ |
| 1500 |
public function commercial_for_sale_to_rent_meta_query( ) { |
| 1501 |
|
| 1502 |
$meta_query = array(); |
| 1503 |
|
| 1504 |
if ( |
| 1505 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1506 |
isset( $_REQUEST['commercial_for_sale_to_rent'] ) && $_REQUEST['commercial_for_sale_to_rent'] == 'for_sale' |
| 1507 |
) |
| 1508 |
{ |
| 1509 |
$meta_query = array( |
| 1510 |
'key' => '_for_sale', |
| 1511 |
'value' => 'yes', |
| 1512 |
'compare' => '=', |
| 1513 |
); |
| 1514 |
} |
| 1515 |
|
| 1516 |
if ( |
| 1517 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1518 |
isset( $_REQUEST['commercial_for_sale_to_rent'] ) && $_REQUEST['commercial_for_sale_to_rent'] == 'to_rent' |
| 1519 |
) |
| 1520 |
{ |
| 1521 |
$meta_query = array( |
| 1522 |
'key' => '_to_rent', |
| 1523 |
'value' => 'yes', |
| 1524 |
'compare' => '=', |
| 1525 |
); |
| 1526 |
} |
| 1527 |
|
| 1528 |
return $meta_query; |
| 1529 |
} |
| 1530 |
|
| 1531 |
/** |
| 1532 |
* Returns a meta query to handle commercial for sale |
| 1533 |
* |
| 1534 |
* @access public |
| 1535 |
* @return array |
| 1536 |
*/ |
| 1537 |
public function commercial_for_sale_meta_query( ) { |
| 1538 |
|
| 1539 |
$meta_query = array(); |
| 1540 |
|
| 1541 |
if ( |
| 1542 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1543 |
isset( $_REQUEST['commercial_for_sale'] ) && $_REQUEST['commercial_for_sale'] == '1' |
| 1544 |
) |
| 1545 |
{ |
| 1546 |
$meta_query = array( |
| 1547 |
'key' => '_for_sale', |
| 1548 |
'value' => 'yes', |
| 1549 |
'compare' => '=', |
| 1550 |
); |
| 1551 |
} |
| 1552 |
|
| 1553 |
return $meta_query; |
| 1554 |
} |
| 1555 |
|
| 1556 |
/** |
| 1557 |
* Returns a meta query to handle commercial to rent |
| 1558 |
* |
| 1559 |
* @access public |
| 1560 |
* @return array |
| 1561 |
*/ |
| 1562 |
public function commercial_to_rent_meta_query( ) { |
| 1563 |
|
| 1564 |
$meta_query = array(); |
| 1565 |
|
| 1566 |
if ( |
| 1567 |
isset( $_REQUEST['department'] ) && $_REQUEST['department'] == 'commercial' && |
| 1568 |
isset( $_REQUEST['commercial_to_rent'] ) && $_REQUEST['commercial_to_rent'] == '1' |
| 1569 |
) |
| 1570 |
{ |
| 1571 |
$meta_query = array( |
| 1572 |
'key' => '_to_rent', |
| 1573 |
'value' => 'yes', |
| 1574 |
'compare' => '=', |
| 1575 |
); |
| 1576 |
} |
| 1577 |
|
| 1578 |
return $meta_query; |
| 1579 |
} |
| 1580 |
|
| 1581 |
/** |
| 1582 |
* Returns a meta query to handle property negotiator |
| 1583 |
* |
| 1584 |
* @access public |
| 1585 |
* @return array |
| 1586 |
*/ |
| 1587 |
public function negotiator_meta_query( ) { |
| 1588 |
|
| 1589 |
$meta_query = array(); |
| 1590 |
|
| 1591 |
if ( isset( $_REQUEST['negotiator_id'] ) && $_REQUEST['negotiator_id'] != '' ) |
| 1592 |
{ |
| 1593 |
$meta_query = array( |
| 1594 |
'key' => '_negotiator_id', |
| 1595 |
'value' => (int)$_REQUEST['negotiator_id'], |
| 1596 |
'compare' => '=' |
| 1597 |
); |
| 1598 |
} |
| 1599 |
|
| 1600 |
return $meta_query; |
| 1601 |
} |
| 1602 |
|
| 1603 |
/** |
| 1604 |
* Returns a meta query to handle property office |
| 1605 |
* |
| 1606 |
* @access public |
| 1607 |
* @param string $compare (default: 'IN') |
| 1608 |
* @return array |
| 1609 |
*/ |
| 1610 |
public function office_meta_query( ) { |
| 1611 |
|
| 1612 |
$meta_query = array(); |
| 1613 |
|
| 1614 |
if ( isset( $_REQUEST['officeID'] ) && $_REQUEST['officeID'] != '' ) |
| 1615 |
{ |
| 1616 |
$meta_query = array( |
| 1617 |
'key' => '_office_id', |
| 1618 |
'value' => (int)$_REQUEST['officeID'], |
| 1619 |
'compare' => '=' |
| 1620 |
); |
| 1621 |
} |
| 1622 |
|
| 1623 |
return $meta_query; |
| 1624 |
} |
| 1625 |
|
| 1626 |
/** |
| 1627 |
* Appends taxonomy queries to an array. |
| 1628 |
* @access public |
| 1629 |
* @param array $tax_query |
| 1630 |
* @return array |
| 1631 |
*/ |
| 1632 |
public function get_tax_query( $tax_query = array() ) { |
| 1633 |
if ( ! is_array( $tax_query ) ) |
| 1634 |
$tax_query = array(); |
| 1635 |
|
| 1636 |
if ( isset($_REQUEST) && !empty($_REQUEST) ) |
| 1637 |
{ |
| 1638 |
foreach ( $_REQUEST as $key => $value ) |
| 1639 |
{ |
| 1640 |
if ( taxonomy_exists($key) && isset( $_REQUEST[$key] ) && !empty($_REQUEST[$key]) && $this->taxonomy_allowed_for_department( $key ) ) |
| 1641 |
{ |
| 1642 |
$tax_query[] = array( |
| 1643 |
'taxonomy' => $key, |
| 1644 |
'terms' => ph_clean( (is_array($value)) ? $value : array( $value ) ) |
| 1645 |
); |
| 1646 |
} |
| 1647 |
} |
| 1648 |
} |
| 1649 |
|
| 1650 |
return array_filter( apply_filters( 'propertyhive_property_query_tax_query', $tax_query, $this ) ); |
| 1651 |
} |
| 1652 |
|
| 1653 |
private function taxonomy_allowed_for_department( $taxonomy ) |
| 1654 |
{ |
| 1655 |
if ( isset( $_REQUEST['department'] ) && $_REQUEST['department'] != '' ) |
| 1656 |
{ |
| 1657 |
$department = ph_clean($_REQUEST['department']); |
| 1658 |
} |
| 1659 |
else |
| 1660 |
{ |
| 1661 |
$department = get_option( 'propertyhive_primary_department', 'residential-sales' ); |
| 1662 |
} |
| 1663 |
|
| 1664 |
switch ( $department ) |
| 1665 |
{ |
| 1666 |
case 'residential-sales': |
| 1667 |
{ |
| 1668 |
if ( in_array( $taxonomy, array('commercial_property_type', 'commercial_tenure', 'furnished') ) ) |
| 1669 |
{ |
| 1670 |
return false; |
| 1671 |
} |
| 1672 |
break; |
| 1673 |
} |
| 1674 |
case 'residential-lettings': |
| 1675 |
{ |
| 1676 |
if ( in_array( $taxonomy, array('commercial_property_type', 'commercial_tenure', 'tenure', 'sale_by', 'price_qualifier') ) ) |
| 1677 |
{ |
| 1678 |
return false; |
| 1679 |
} |
| 1680 |
break; |
| 1681 |
} |
| 1682 |
case 'commercial': |
| 1683 |
{ |
| 1684 |
if ( in_array( $taxonomy, array('property_type', 'tenure', 'parking', 'outside_space', 'furnished') ) ) |
| 1685 |
{ |
| 1686 |
return false; |
| 1687 |
} |
| 1688 |
break; |
| 1689 |
} |
| 1690 |
} |
| 1691 |
|
| 1692 |
|
| 1693 |
return true; |
| 1694 |
} |
| 1695 |
|
| 1696 |
/** |
| 1697 |
* Layered Nav Init |
| 1698 |
*/ |
| 1699 |
public function layered_nav_init( ) { |
| 1700 |
|
| 1701 |
} |
| 1702 |
|
| 1703 |
/** |
| 1704 |
* Layered Nav post filter |
| 1705 |
* |
| 1706 |
* @param array $filtered_posts |
| 1707 |
* @return array |
| 1708 |
*/ |
| 1709 |
public function layered_nav_query( $filtered_posts ) { |
| 1710 |
|
| 1711 |
} |
| 1712 |
|
| 1713 |
/** |
| 1714 |
* Price filter Init |
| 1715 |
*/ |
| 1716 |
public function price_filter_init() { |
| 1717 |
|
| 1718 |
} |
| 1719 |
|
| 1720 |
/** |
| 1721 |
* Price Filter post filter |
| 1722 |
* |
| 1723 |
* @param array $filtered_posts |
| 1724 |
* @return array |
| 1725 |
*/ |
| 1726 |
public function price_filter( $filtered_posts ) { |
| 1727 |
|
| 1728 |
} |
| 1729 |
|
| 1730 |
} |
| 1731 |
|
| 1732 |
endif; |
| 1733 |
|