You can add text search to a View using the Post search filter which returns only posts where the specified string is found in the post title or, optionally, the post body. It also allows you to add a text search box to your page or as part of a Custom search form for your View.

Note: If you just want to add a Search box to your view or as part of a Custom search form, then you do not need to add the filter manually. Follow the instructions in the Add a search box for visitors section below. Views will automatically create a Query Filter for you.

Add a Search Query Filter to your View

In the Query Filter section of your View, click on Add a filter. Select to filter by Post search from the filter dropdown.

Add Search filter
Add Search filter

This will add the Search configuration options:

Search Settings
Search Settings

Search for a specific text

This will limit the View results to only those posts which contain the text you have entered in the filter.

Search for a text, set by the View shortcode attribute

You can limit the query results to include only posts containing a string supplied by a shortcode attribute. You can specify the attribute name, though Views will suggest search by default.

The attribute name used in the filter needs to match the attribute added to the wpv-view shortcode where the View is inserted.

Imagine you have a site where your registered users have a dashboard page and in their profile they can specify a favorite sport. You might insert a View on the dashboard page which, for the currently logged-in user, lists posts about their favorite sport.

The shortcode to insert the View could use the User custom field to specify the text search attribute, like so:

[wpv-view name="favourite-sport-posts" search="[types usermeta='favourite-sport' user_current='true'][/types]"]

Search in content or titles

You can choose to search just in the post title, or in both the title and post content.

Filter by Post search – where to search
Filter by Post search – where to search

Add a search box for visitors

This option will allow you to add a search box to your page.

Scroll down to the Search and Pagination section - you will need to ensure that the cursor is within the filter control shortcode:

Search filter controls
[wpv-filter-controls] [/wpv-filter-controls]

Click the Text search button to add a search box to your View.

Insert Search shortcode
Insert Search shortcode

To complete your search form, you'll want to add a Submit button:

Search submit button
[wpv-filter-submit name="Search"]

When you add your View to a page, the search box will be displayed immediately above your view results.

Filter by Post search - search form
Filter by Post search - search form

You can change where your search form is displayed, remove it from your results page and insert it as a sidebar widget or on another page. Read Custom search - Displaying just the search form to find out how.