Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to have two separate search functions. The first is fine how it is, the second, I would like to only search titles. I have tried the code suggested [here]( Two Search boxes: One only searches Titles, the other searches all content?), but do not know how to make the function conditional on the hidden value ('by-ref') in my search form.

<form method="get" id="searchform" action="<?php bloginfo('home'); ?>/">
<input type="text" value="" name="s" id="search-text" />
<input type="hidden" name="search-type" value="by-ref" />
<input name="submit" type="submit" value="Go" />
</form>
share|improve this question

1 Answer 1

It was not so hard and I have solved the problem, so for any one else stuck, just add:

if ( isset($_GET['search-type']) == 'by-ref' ) { add_filter( 'posts_search', '__search_by_title_only', 500, 2 ); }

where 'by-ref' is set in form as

input type="hidden" name="search-type" value="by-ref"

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.