【发布时间】:2011-08-24 20:47:40
【问题描述】:
我在 Wordpress 中使用的搜索插件 (Relavenssi) 允许用户在搜索词中添加 quotes 以搜索短语,例如“搜索短语”。
我将如何对其进行编码,以便当用户选择一个名为“精确匹配”的单选框/复选框时,quotes 会自动添加到搜索查询中,而不是由用户添加到搜索框中?
非常感谢您的帮助,S。
搜索表单代码如下:
<form action="<?php bloginfo('home'); ?>/" method="post">
<div class="search-icon">
<label for="search" accesskey="4" class="hidden">Search the site</label>
<input type="text" name="s" id="search" value="Enter search term" onblur="this.value = this.value || this.defaultValue;" onfocus="this.value = '';" />
<input type="submit" name="submit" value="GO" class="s-btn" />
<p><a href="#" id="search-anchor">Search Options</a></p>
<div class="option-slide">
<input type="radio" name="sentence" value="" checked="checked" /><label>All Words</label><br />
<input type="radio" name="sentence" value="???" /><label>Exact Match</label>
</div>
</div>
</form>
编辑:根据下面@Tristar Web Design 的回答,我现在在我的搜索表单下方添加了这个php 代码,尽管它不能正常工作。它回显正常,但没有将查询传回。如何将更新的搜索查询传递/发送回 Wordpress?
if(isset($_POST['s']) && $_POST['sentence'] == 'exact') {
$_POST['s'] = '"'.get_search_query().'"';
echo $_POST['s'];
} else {
echo "2";
}
【问题讨论】: