I searched for this a long time just to find it was very easy to do, so I hope this helps you too.
The objective of this short guide is to explain how to
build a view in Drupal 7 that will let you search for part of a title of a specific content. Let's say your site is about music and you have a content type called "Song", which has an artist and a title. Now let's say you want to search on the title and let the user select a search term.
It's very easy to get distracted by the "Contextual filters" option. If you wonder what this is, I recommend you have a look at this
excellent video tutorial on Drupal 7 views by Johan Falk. There is also a long series of Drupal views tutorials linked to that one.
Now if you want to do what we suggested, there are only a few short things to do:
1. Create a view
To create a new view (you'll need it), follow the
Structure -> Views menu and click
Add new view link (see red underline in screenshot).
2. Define view settings
The view settings should be defined to what suits you best. Let's say you want to change the title, the URL and give it a specific content type to look for. See options underlined in red in the next screenshot. The"Title (links)" option is selected as a display format so that the results will link directly to the song.
3. Add fields
Once the basic parameters of your view have been set, you can add the fields you want to show in the results list. Here, we added the artist field.
4. Select content title filter
Now comes the real trick. In order to allow users to search for your songs titles, you will need to "expose" the corresponding title filter to your users. In order to do that, you first need to have a song title filter. That's what you're going to add clicking on the "Add" button next to "Filter criteria". In the filter types list, select Content: Title (as you are already inside a view on the Songs content type.
Click "Add and configure filter criteria".
5. Set the filter settings
You'll first get a form like this:
Update all the settings (starting by the "Expose criteria" checkbox) so you get something similar to this:
You want to pay attention to the filter type, which should say "Contains", so that any *part of* a title will give you the song with that title. To save, click "Apply (all displays)".
6. Save the view
Your view should now look something like this. Just click the "Save" button on the top of the view to apply your changes.
7. Enjoy
Now click the "View page" button on the right side of your view panel. This will lead you to a page with... a search box and a list of songs! Well done!
Comments
thank you very much for this tutorial :)
THANK YOU!!!
After some 2 hours wrecking my brain on D7 Views, your tutorial helped 100%.
Peace brother, luck and good fortune to you.
Good karma.
This is awesome! Is there a way to display this as a block, and the once you click apply it goes to a results page?
Thank You...
How would you get a search term, aka arg(2), be the keyword for Content: Title contains?
Thanks a bunch, helped me!
(i forgot to choose 'contains' instead of 'is equal to'