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]( https://wordpress.stackexchange.com/questions/27407/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" />

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"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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