WordPress查询分类中的多个术语

时间:2012-05-29 00:46:00

标签: php mysql wordpress wordpress-plugin

我正在开发一个网站,我需要在该网站中查询分类中的多个术语。目前,我有以下内容适用于下拉菜单。

function ct_search_form_select_quick($name, $taxonomy_name = null) {
    global $search_values;

    if (!$taxonomy_name) {
        $taxonomy_name = $name;
    }
    ?>
    <select id="ct_<?php echo $name; ?>" name="ct_<?php echo $name; ?>">
        <option value="0"><?php _e('Any', 'theme_textdomain'); ?></option>
        <?php foreach( get_terms($taxonomy_name, 'hide_empty=0') as $t ) : ?>
            <?php if ($search_values[$name] == $t->slug) { $selected = 'selected="selected" '; } else { $selected = ''; } ?>
            <option <?php echo $selected; ?>value="<?php echo $t->slug; ?>"><?php echo $t->name; ?></option>
        <?php endforeach; ?>
    </select>

但是,我希望能够在单个分类中查询多个术语。

我有以下代码,允许我选择术语并输出第一学期的结果,但忽略第二学期。 URL以

输出
  

?property_type = condo-duplex&amp; property_type = condo-loft&amp; ct_price_from =&amp; ct_price_to =&amp; ct_mls =&amp; property-search = true&amp; x = 32&amp; y = 18,需要输出为?property_type =公寓双工,公寓膨松&安培; ct_price_from =安培; ct_price_to =安培; ct_mls =安培;属性的搜索=真安培; X = 32&安培; Y = 18

function ct_search_form_select($name, $taxonomy_name = null) {
    global $search_values;

    if (!$taxonomy_name) {
        $taxonomy_name = $name;
    }
    ?>
        <input type="checkbox" value="0" name="ct_<?php echo $name; ?>"><?php _e('Any', 'theme_textdomain'); ?>
        <?php foreach( get_terms($taxonomy_name, 'hide_empty=0') as $t ) : ?>-->
                    <?php if ($search_values[$name] == $t->slug) { $selected = 'selected="selected" '; } else { $selected = ''; } ?>

<input type="checkbox" name="<?php echo $name; ?>" value="<?php echo $t->slug; ?>"><?php echo $t->name; ?>
        <?php endforeach; ?>

2 个答案:

答案 0 :(得分:0)

对您来说有多方便:

已经有一个惊人的插件可以实现这个功能:

http://wordpress.org/extend/plugins/query-multiple-taxonomies/

请在此处查看:

productionlocations.com/locations

答案 1 :(得分:0)

一年后不确定这是否有用,但我遇到了类似的问题,这就是我提出的问题

function ct_search_form_check($name, $taxonomy_name = null) {
global $search_values;

    if (!$taxonomy_name) {
        $taxonomy_name = $name;
    }

?>
    <?php foreach( get_terms($taxonomy_name, 'hide_empty=0') as $t) : ?>
        <?php if ($search_values[$name] == $t->slug) { $selected = 'checked="checked"'; } else { $selected = ''; } ?>
            <div><input id="ct_<?php echo $name; ?>" name="ct_<?php echo $name; ?>" type="checkbox" style="margin-right:5px; margin-left:5px" <?php echo $selected; ?>value="<?php echo $t->slug; ?>"><?php echo $t->name; ?><span style="margin-left:10px"></span></input></div>
           <?php 
           $data = array();
                while (list($name, $t->slug) = each($arr)) {
                   $data[] = "$name";
                }
                echo implode($data); 
                if (!empty($_GET['ct_'])) { 
                    $url = str_replace('&ct_=', '%2c', $_SERVER['QUERY_STRING']);
                    header("Location: ?$url");
                } ?>
    <?php endforeach; ?>