在wordpress主题我已经基于自定义分类设置一些搜索过滤器,将使用URL结构类似查询职位:的WordPress/PHP:添加搜索串到现有的查询字符串
http://myblog.com/?taxonomy1=term1+term2&taxonomy2=term3+term4
除这些过滤器我想集成文本搜索,但不知道如何将搜索查询(例如?s=mysearchhere
)附加到现有的分类查询中。因此,在总我想要的形式,在提交,导致它结合了两个字符串的URL:
“http://myblog.com/?taxonomy1=term1+term2 & taxonomy2 = TERM3 + term4 & S = mysearchhere”
到目前为止,我已经试过了具有以下功能生成的搜索表单:
function remove_querystring_var($url, $key) {
$url = preg_replace('/(.*)(?|&)' . $key . '=[^&]+?(&)(.*)/i', '$1$2$4', $url . '&');
$url = substr($url, 0, -1);
return $url;
}
function apl_search_form($echo = true) {
do_action('get_search_form');
$search_form_template = locate_template('searchform.php');
if ('' != $search_form_template) {
require($search_form_template);
return;
}
$url = $_SERVER["REQUEST_URI"];
$action = remove_querystring_var($url,'s');
$form = '<form role="search" method="get" id="searchform" action="' . $action . '" >
<div><label class="screen-reader-text" for="s">' . __('Search for:') . '</label>
<input type="text" value="' . get_search_query() . '" name="s" id="s" />
<input type="submit" id="searchsubmit" value="'. esc_attr__('Search') .'" />
</div>
</form>';
if ($echo)
echo apply_filters('get_search_form', $form);
else
return apply_filters('get_search_form', $form);
}
这似乎并不奏效。这个问题比我看起来更复杂吗?还是我在正确的轨道上?有谁知道这种直接的编码方式吗?
非常感谢!
你能更具体地说“似乎没有工作吗?”您的表单值将自动添加到网址上,您正在进行“获取”和“发布”。 – 2011-12-27 04:17:55