Two Search Boxes: one all content, one only titles

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" />
</form>

Related posts

Leave a Reply

1 comment

  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”