2011-01-11 157 views
1

我要讓自定義搜索的WordPress:自定義搜索

這是從形式輸出網址http://alessandro.host/?country=Italy&area=Milan&type=luxury-hotels

,並接受這樣的解釋:

  • $ _GET [ '國家'] = >這是來自post_meta的值
  • $ _GET ['area'] =>這是來自post_meta的值
  • $ _GET ['type'] =>這是帖子類別

我怎麼能做這個自定義搜索?

回答

2

我在WordPress 3.1退房先進的元數據查詢scribu的解釋,以幫助您: http://scribu.net/wordpress/advanced-metadata-queries.html

而且,看看WordPress的對WP_Query文檔: http://codex.wordpress.org/Function_Reference/WP_Query

在你的情況下,聽起來像所有你需要的是這樣的:

<?php 

$country = $_GET['country']; 
$area = $_GET['area']; 
$type = $_GET['type']; 

query_posts(array(
    'category_name' => $type,   
    'meta_query' => array(
     array(
      'key' => 'country', 
      'value' => $country, 
     ), 
     array(
      'key' => 'area', 
      'value' => $area, 
     ) 
    ) 
)); 

// now do the loop as normal 

?>