WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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" />
share|improve this question

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


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.