1

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

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&property_type=condo-loft&ct_price_from=&ct_price_to=&ct_mls=&property-search=true&x=32&y=18,需要输出为?property_type=condo-duplex,condo-loft&ct_price_from=&ct_price_to=&ct_mls=&property-search=真&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; ?>
4

2 回答 2

0

对您来说有多方便:

已经有一个了不起的插件可以实现这个确切的功能:

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

在这里查看它的实际效果:

productionlocations.com/locations

于 2012-05-29T00:49:20.587 回答
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; ?>

于 2013-03-03T06:37:32.650 回答