为PHP查询添加多个选项

时间:2016-07-23 16:43:23

标签: php wordpress

我有一个属性列表网站,我需要有关过滤搜索结果的代码的帮助。以下代码包括合同类型为" southern-oregon"的所有属性。我希望它还包括合同类型=" medford-office"。有人能告诉我如何将其添加到代码中吗?

以下是代码:

<?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') { 
?>

1 个答案:

答案 0 :(得分: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', ]

我猜这会做IN,基本上是OR