Is it not OK to accept a value from $_GET as the key in a WP Meta Query? I'm not sure why this code doesn't return any results...
BOTH the queries for Price as well as bedrooms do not return any results. Is my code incorrect? Any help will be much appreciated..
<?php
if ( get_query_var('paged') ) {
$paged = get_query_var('paged');
} else if ( get_query_var('page') ) {
$paged = get_query_var('page');
} else {
$paged = 1;
}
$args = array(
'post_type' => 'property',
'paged' => $paged
);
if($_GET['beds'] >= 1) {
$args['meta_query'][] = array(
'key' => $_GET['beds'],
'value' => array('pyre_BHK-A','pyre_BHK-B','pyre_BHK-C','pyre_BHK-D','pyre_BHK-E'),
'compare' => 'IN'
);
}
if(($_GET['price-max'] >= 1)&&($_GET['price-min'] >= 1)) {
$args['meta_query'][] = array(
'relation' => 'OR',
array(
'key' => 'pyre_price',
'value' => array($_GET['price-min'],$_GET['price-max']),
'compare' => 'BETWEEN',
'type' => 'numeric'
),
array(
'key' => 'pyre_pricem',
'value' => array($_GET['price-min'],$_GET['price-max']),
'compare' => 'BETWEEN',
'type' => 'numeric'
)
);
}
query_posts($args);
if(have_posts()):
?>
<?php
while(have_posts()): the_post();
?>
<?php get_template_part( 'property-listing' ); // Navigation bar (property-listing.php) ?>
<?php endwhile; ?>
<?php 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 endif; ?>
$_GET
and why you are comparing it using>= int