Created
September 30, 2013 16:00
-
-
Save sentisoft/6766004 to your computer and use it in GitHub Desktop.
Problem with custom search form for WP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php get_header(); ?> | |
<div id="content" class="site-content" role="main"> | |
<?php | |
// get all gets | |
foreach($_GET as $name=>$value) { | |
$search_get[$name] = $value; | |
} | |
global $wp_query; | |
$s_false = false; | |
// set custom post type | |
$post_type = array('property'); | |
// get custom taxonomies | |
if($search_get['tip']) | |
$tax_tip = $search_get['tip']; | |
if($search_get['status']) | |
$tax_status = $search_get['status']; | |
if($search_get['grad']) | |
$tax_grad = $search_get['grad']; | |
// check beds custom fields | |
if($search_get['broj_soba']) | |
$meta_query_broj_soba = array( | |
'key' => 'broj_soba', | |
'value' => $search_get['broj_soba'], | |
'compare' => '=', | |
'type' => 'BINARY' | |
); | |
// check baths custom fields | |
if($search_get['broj_kupatila']) | |
$meta_query_broj_kupatila = array( | |
'key' => 'broj_kupatila', | |
'value' => $search_get['broj_kupatila'], | |
'compare' => '=', | |
'type' => 'numeric' | |
); | |
// check price custom fields | |
if ($search_get['cena'] == '0 - 49.999') { | |
$meta_query_cena = array( | |
'key' => 'cena', | |
'value' => '49', | |
'compare' => '<=', | |
'type' => 'numeric' | |
); | |
} elseif ($search_get['cena'] == '50.000 - 99.999') { | |
$meta_query_cena = array( | |
'key' => 'cena', | |
'value' => array( '50', '99' ), | |
'compare' => 'BETWEEN', | |
'type' => 'numeric' | |
); | |
} elseif ($search_get['cena'] == '100.000 - 499.999') { | |
$meta_query_cena = array( | |
'key' => 'cena', | |
'value' => array( '100', '499' ), | |
'compare' => 'BETWEEN', | |
'type' => 'numeric' | |
); | |
} elseif ($search_get['cena'] == '500.000+') { | |
$meta_query_cena = array( | |
'key' => 'cena', | |
'value' => '500', | |
'compare' => '>=', | |
'type' => 'numeric' | |
); | |
} else { | |
$meta_query_cena = array( | |
'key' => 'cena', | |
'value' => '1', | |
'compare' => '>=', | |
'type' => 'numeric' | |
); | |
} | |
// build meta query | |
$meta_query = array(); | |
if(!empty($meta_query_broj_soba)) | |
array_push($meta_query, $meta_query_broj_soba); | |
if(!empty($meta_query_broj_kupatila)) | |
array_push($meta_query, $meta_query_broj_kupatila); | |
if(!empty($meta_query_cena)) | |
array_push($meta_query, $meta_query_cena); | |
if(!empty($search_get)) : | |
$args = array( | |
'post_type' => $post_type, | |
'tip' => $tax_tip, | |
'status' => $tax_status, | |
'grad' => $tax_grad, | |
'order' => 'DESC' | |
); | |
// add meta query | |
if(!empty($meta_query)) | |
$args = array_merge($args, array('meta_query' => $meta_query)); | |
query_posts($args); | |
if($s_false) : | |
$wp_query->is_home = false; | |
$wp_query->is_search = true; | |
endif; | |
endif; | |
get_template_part( 'nekretnine', 'property-search' ); | |
?> | |
</div><!-- #content --> | |
<div id="sidebar"> | |
<?php require_once(get_template_directory() . '/includes/pretraga-nekretnine.php'); // poziv za formu za pretragu nekretnina ?> | |
<?php require_once(get_template_directory() . '/includes/baneri.php'); // poziv za bannere ?> | |
</div> | |
<?php get_footer(); ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment