[英]How can I replace a character in a wordpress search query?
For example, how would I go about replacing www.example.com/search/mark+twain
with www.example.com/search/mark_twain
? 例如,如何将
www.example.com/search/mark+twain
替换为www.example.com/search/mark_twain
?
The form to search looks like this: 搜索表单如下所示:
<form role="search" method="get" id="searchform" action="<?php echo home_url('/'); ?>">
<label class="visuallyhidden" for="s"><?php _e('Search for:', 'roots'); ?></label>
<input type="text" value="" name="s" id="s" placeholder="<?php _e('Search Courses/Material'); ?> ">
<input type="submit" id="searchsubmit" value="<?php echo attribute_escape(__('Search')); ?>" class="button">
</form>
I'm not quite sure how you're using this or where exactly you're using that query, but you could always use string replace: 我不太确定您是如何使用此查询的,或者您到底在何处使用该查询,但是您始终可以使用字符串替换:
str_replace('+','_',$query)
That's the best answer I can give with this vague a question. 这是我能给这个模糊问题提供的最佳答案。
For jquery (which wordpress makes use of) you could do something like: 对于jquery(wordpress使用的jquery),您可以执行以下操作:
$('#sear form').submit(function(){ $(this).val($(this).val().replace(' ','_')); });
I think that's correct. 我认为是正确的。 I'm not where I can try it, but it should work.
我不是可以尝试的地方,但是应该可以。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.