You have some errors on how meta_query
array is setted for price-max
and price-min
.
Also in your code will be an issue if no $_GET['beds']
are sended but $_GET['price-min']
and $_GET['price-max']
are. this because the $args['meta_query']
array is setted inside if($_GET['beds'] >= 1)
.
Moreover your code will throw a lot of notices if the GET
are not sended, you have to check if $_GET
variables are set before using and, in addition, you should ensure them are numeric values if you want to use as numeric.
Finally, query_posts
should always be avoided, use WP_Query instead.
This code should work, but is untested:
<?php
if ( ! is_front_page() ) {
$paged = get_query_var('paged') ? : 1;
} else {
$paged = get_query_var('page') ? : 1;
}
$beds = isset($_GET['beds']) && intval($_GET['beds']) ? $_GET['beds'] : 0;
$max = isset($_GET['price-max']) && intval($_GET['price-max']) ? $_GET['price-max'] : 0;
$min = isset($_GET['price-min']) && intval($_GET['price-min']) ? $_GET['price-min'] : 0;
$args = array(
'post_type' => 'property',
'paged' => $paged
);
if( $beds >= 1) {
$args['meta_query'][] = array(
'key' => $beds, // are you sure for that?
'value' => array('pyre_BHK-A','pyre_BHK-B','pyre_BHK-C','pyre_BHK-D','pyre_BHK-E'),
'compare' => 'IN'
);
}
if( ($max >= 1) && ($min) ) {
if ( ! isset($args['meta_query']) ) $args['meta_query'] = array();
$args['meta_query']['relation'] = 'OR';
$args['meta_query'][] = array(
'key' => 'pyre_price',
'value' => array($min, $max),
'compare' => 'BETWEEN',
'type' => 'numeric'
);
$args['meta_query'][] = array(
'key' => 'pyre_pricem',
'value' => array($min, $max),
'compare' => 'BETWEEN',
'type' => 'numeric'
);
}
$query = new WP_Query($args);
if( $query->have_posts() ) : while( $query->have_posts() ): $query->the_post();
get_template_part( 'property-listing' );
// Navigation bar (property-listing.php)
endwhile;
else:
?>
<h3><?php echo of_get_option('search_results_none_title', 'No properties were found which match your search criteria.'); ?></h3>
<p><?php echo of_get_option('search_results_none_content', 'Try broadening your search to find more results.'); ?></p>
<?php
wp_reset_postdata();
endif;
?>