我认为像这样的事情你最好自己写。
看看:http : //www.catalysthomes.co.uk/homes-for-sale/
属性已加载到CPT中,并且我在边栏中有自己的自定义搜索。在该搜索中,它搜索许多内容,例如分类法,自定义字段和按日期价格排序等。
那么我该如何实现呢?我将表单提交到页面模板,然后从那里处理帖子数据并根据搜索条件构建一个新的WP_query。我使用会话来存储搜索变量,以便可以对结果进行分页。
WP_Query非常强大。看看:http : //codex.wordpress.org/Class_Reference/WP_Query
您可以在其中meta_query
查询多个自定义字段,并用于tax_query
查询分类法,还有更多内容。以下是我的构建方式,可为您提供一个想法。
模板文件:
<?php
$temp = $wp_query;
$wp_query = NULL;
$args = array();
?>
<?php include("functions/Homes-for-sale/propertyrawresults.php"); ?>
<?php include("functions/Homes-for-sale/propertysearchresults.php"); ?>
<?php
$args['post_type'] = "homes-for-sale";
$args['showposts'] = 10;
$args['paged'] = $paged;
$wp_query = new WP_Query($args);
?>
<?php include("functions/Homes-for-sale/propertylistlayout.php"); ?>
原始结果
<?php
if($_POST['sortby']) {
$_SESSION['prop_selectedsortby'] = $_POST['sortby'];
}
switch($_SESSION['prop_selectedsortby']) {
case "name-asc": $args['order'] = "ASC"; $args['orderby'] = "title"; break;
case "name-desc": $args['orderby'] = "title"; break;
case "price-asc": $args['order'] = "ASC"; $args['orderby'] = "meta_value_num"; $args['meta_key'] = "chb_homes_for_sale_specifics_fmv"; break;
case "price-desc": $args['orderby'] = "meta_value_num"; $args['meta_key'] = "chb_homes_for_sale_specifics_fmv"; break;
case "date-asc": $args['order'] = "ASC"; break;
default: /* No need to set arguments here as wp query defaults */ break;
}
$selectedsortby[$_SESSION['prop_selectedsortby']] = " selected=\"selected\"";
?>
搜索结果
<?php
if( ! empty( $_SESSION['s_property_ptype'] ) ) {
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_types_nbrs',
'value' => $_SESSION['s_property_ptype']
);
}
if( ! empty( $_SESSION['s_property_development'] ) ) {
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_ofdevelopment',
'value' => $_SESSION['s_property_development']
);
}
if( isset( $_SESSION['s_property_area'] ) && 0 != $_SESSION['s_property_area'] ) {
$args['tax_query'][] = array(
'taxonomy' => 'areas',
'field' => 'id',
'terms' => array( (int) $_SESSION['s_property_area'] ),
);
}
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_specifics_bedrooms',
'value' => $_SESSION['s_property_bedrooms_min'],
'compare' => '>=',
'type' => 'SIGNED'
);
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_specifics_bedrooms',
'value' => $_SESSION['s_property_bedrooms_max'],
'compare' => '<=',
'type' => 'SIGNED'
);
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_specifics_bathrooms',
'value' => $_SESSION['s_property_bathrooms_min'],
'compare' => '>=',
'type' => 'SIGNED'
);
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_specifics_bathrooms',
'value' => $_SESSION['s_property_bathrooms_max'],
'compare' => '<=',
'type' => 'SIGNED'
);
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_specifics_fmv',
'value' => $_SESSION['s_property_min_price'],
'compare' => '>=',
'type' => 'SIGNED'
);
$args['meta_query'][] = array(
'key' => 'chb_homes_for_sale_specifics_fmv',
'value' => $_SESSION['s_property_max_price'],
'compare' => '<=',
'type' => 'SIGNED'
);
?>
列表布局
只是一个标准的WP循环以显示帖子摘录和信息。