2016-07-23 111 views
-3

我有一個房產列表網站,我需要幫助您篩選搜索結果的代碼。下面的代碼包括所有合同類型爲「南部 - 俄勒岡州」的房產。我希望它也包括合同類型=「medford-office」。有人能告訴我如何將其添加到代碼?向PHP查詢添加多個選項

下面是代碼:

<?php 
echo $div; $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; 
query_posts(array('post_type'=>'property','post_status'=>'publish','paged'=>$paged, 
        'author'=>$agent, 'property-contract-type'=>'southern-oregon')); 
if(have_posts()):while(have_posts()):the_post(); 
$property_images = get_post_meta(get_the_ID(),'imic_property_sights',false); 
$total_images = count($property_images); 
$property_term_type = ''; 
$property_area = get_post_meta(get_the_ID(),'imic_property_area',true); 
$property_baths = get_post_meta(get_the_ID(),'imic_property_baths',true); 
$property_beds = get_post_meta(get_the_ID(),'imic_property_beds',true); 
$property_parking = get_post_meta(get_the_ID(),'imic_property_parking',true); 
$property_address = get_post_meta(get_the_ID(),'imic_property_site_address',true); 
$property_city = get_post_meta(get_the_ID(),'imic_property_site_city',true); 
$property_price = get_post_meta(get_the_ID(),'imic_property_price',true); 
$contract = wp_get_object_terms(get_the_ID(), 'property-contract-type', 
           array('fields'=>'ids')); 
$property_id = get_post_meta(get_the_ID(),'imic_property_site_id',true); 
$property_area_location = wp_get_object_terms(get_the_ID(), 'city-type'); 
$sl = ''; 
$total_area_location = count($property_area_location); 
$num = 1; 
foreach($property_area_location as $sa) { 
    $conc = ($num!=$total_area_location)?'->':''; 
    $sl .= $sa->name.$conc; $num++; 
} 
// We get Longitude & Latitude By Property Address 
$property_longitude_and_latitude=get_post_meta(get_the_ID(),'imic_lat_long',true); 
if(!empty($property_longitude_and_latitude)){ 
    $property_longitude_and_latitude = explode(',', 
    $property_longitude_and_latitude); 
}else{ 
    $property_longitude_and_latitude=getLongitudeLatitudeByAddress($property_address); 
} 
global $imic_options; 
$currency_symbol = imic_get_currency_symbol($imic_options['currency-select']); 
$src = wp_get_attachment_image_src(get_post_thumbnail_id(),'150-100-size'); 
if(!empty($src)): 
    $image_container= '<span class ="property_image_map">'.$src[0].'</span>'; 
else: 
    $image_container=''; 
endif; 
if(!empty($contract)) { 
    $term = get_term($contract[0], 'property-contract-type'); $property_term_type = $term->name; 
} 
if($design_type=='listing') { 
?> 
+4

您是否考慮聘請程序員? – melpomene

+0

我有一個程序員爲我建立了這個,但他現在不可用。我只是想對代碼進行快速編輯以修復我們的實時網站。我很感激幫助,我明白這可能是一個非常簡單的問題。 – Rob

+1

激發你的程序員。 – trincot

回答

0

我希望這是你的過濾系統的核心(顯著重新格式化爲可讀性 - 讓開發者來解決這個問題,請):

query_posts(
    array(
     'post_type' => 'property', 
     'post_status' => 'publish', 
     'paged' => $paged, 
     'author' => $agent, 
     'property-contract-type' => 'southern-oregon' 
    ) 
); 

在猜測,嘗試用數組替換'southern-oregon',因此:

['southern-oregon', 'medford-office', ] 

I會猜測這會做一個IN,這本質上是一個OR

+1

這樣做的竅門,我重新格式化的代碼,並添加數組,現在它正常工作。 – Rob