Saya pikir sesuatu seperti ini Anda sebaiknya menulis sendiri.
Lihatlah: http://www.catalysthomes.co.uk/homes-for-sale/
Properti dimuat ke CPT dan saya punya pencarian sendiri di sidebar. Dari pencarian itu mencari beberapa hal seperti taksonomi, bidang khusus dan pemesanan berdasarkan harga tanggal dll.
Jadi, bagaimana saya mencapai ini? Saya mengirimkan formulir ke templat halaman dan dari sana saya berurusan dengan data posting dan membangun WP_query baru berdasarkan kriteria pencarian. Saya menggunakan sesi untuk menyimpan variabel pencarian sehingga saya bisa memberi peringkat hasil.
WP_Query sangat kuat. Lihatlah: http://codex.wordpress.org/Class_Reference/WP_Query
Di sana Anda dapat menggunakan meta_query
untuk menanyakan beberapa bidang khusus dan menggunakan tax_query
untuk menanyakan taksonomi Anda, plus ada lebih banyak. Di bawah ini adalah bagaimana saya dibangun untuk memberi Anda ide.
File Templat:
<?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"); ?>
Hasil Mentah
<?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\"";
?>
Hasil Pencarian
<?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'
);
?>
List Layout
Hanya loop WP standar untuk menampilkan kutipan dan info posting.