WordPress Search

Describe WordPress Search Functionality

WordPress search works by taking the user entered data and looking through the database. The data is returned based on how relevant it is to the search query. It first looks to match post titles and after that it matches in the post content. Once the data is collected, WordPress looks for the file search.php to use to display the data. If that file is not found, it uses index.php as a backup.

Explain the role of the URI when searching

When a search is conducted, Wordpress uses the url of https://www.websitename.com/index.php?s=yoursearchterm. The ? denotes data being sent through the URI. The 's' is WordPress's way of showing what follows is the term being searched for.

Explain how to show the current/active search term in search form field

The php function, get_search_query(); will return the value of the current search. This function is used in the general-template.php file by default to check for a current search and display it in the search form text box. This is the line of code in that file that looks for the current search term:

<input type="search" class="search-field" placeholder="' . esc_attr_x( 'Search …', 'placeholder' ) . '" value="' . get_search_query() . '" name="s" /> >

Specifically the part assigning the value="". This is where get_search_query() runs and shows the value. If there is not a search currently being conducted, the placeholder value of "Search..." will show instead.

Summary of the Documentation

WordPress search is a very important part of a site, especially if contains a lot of content. It allows people to search the site to find the topics they are looking for quickly. The layout of the search results can be customzied by creating custom layouts in the search.php file. Additional customization to search can be done by limiting which categories are searched, allow the user to choose which category to search, and decide whether to include only pages or posts in a search. Also, the url of the search result page can be updated from ?s=searchterm to be nicer looking as webite.com/search/searchterm. Small functionality tweaks can make WordPress search more effective for the end user and more user friendly in appearance as well.

Sources