Wordpress:自定义搜索

时间:2011-01-11 04:08:49

标签: php wordpress wordpress-plugin

我想进行自定义搜索

这是http://alessandro.host/?country=Italy&area=Milan&type=luxury-hotels

形式的输出网址

这就是解释:

  • $ _ GET ['country'] =>这是来自post_meta
  • 的值
  • $ _ GET ['area'] =>这是来自post_meta
  • 的值
  • $ _ GET ['type'] =>这是帖子类别

我如何进行自定义搜索?

1 个答案:

答案 0 :(得分:2)

我会在WordPress 3.1中查看scribu对高级元数据查询的解释,以帮助您: http://scribu.net/wordpress/advanced-metadata-queries.html

另外,请看一下关于WP_Query的WordPress文档: 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

?>