Create a view to search on content title in 7 steps in Drupal 7

  1. 1-create-view
  2. 2-view-create-form
  3. 3-added-artist-field
  4. 5-initial-filter-settings
  5. 4-select-content-title-filter
  6. 6-filter-update
  7. 7-save-view
  8. 8-enjoy

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!

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on TumblrEmail this to someone

6 Comments

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *