Adding Search
The search feature lets you setup a basic search form for your directory.
If you already have setup filters for your directory following the instructions in Adding and Managing Filters, then you may not feel the need for setting up another interface for finding listings. However if there is a large number of filters, providing a basic search form as the initial entry point to your directory should greatly help in improving user experience. This way, for example, users can first make a general search using the search form on the home page and then narrow down the search results using the filters on the directory main page.
Enable search
Follow these steps to enable search for your directory:
Login to your website if not yet logged in and go to the WordPress administration dashboard.
Click Directories in the admin sidebar.
Under the All Directories tab, click the gear icon in the row of the directory to edit.
Under the Settings tab, scroll down the page and select Yes for Enable search.
Scroll further down and click Save Changes.
By default, you can view the search form of your directory by appending /search to the URL of the directory main page. For example if your directory main page is http://example.com/directory, the search form can be viewed at http://example.com/directory/search. However, if you are using the [drts-directory-view] shortcode to display your directory on the directory main page, you will need to use the following URL: http://example.com/directory?drts_action=search.
Configuring search
Follow the steps below to configure and customize the search form for your directory.
Login to your website if not yet logged in and go to the WordPress administration dashboard.
Click Directories in the admin sidebar.
Under the All Directories tab, click the gear icon in the row of the directory to edit.
Under the Content Types tab, click the Edit button in the Listing row.
Click the Search sub-tab under the Edit tab.
Keyword Search
The keyword search field lets visitors enter random keywords that are then matched against field values of listings in the directory. By default, only values of the listing title and description fields are matched, however you can also include taxonomy terms and/or other custom fields that support keyword search.
Hide this field - Whether to hide the keyword search field from the search form.
Min. length of keywords in characters - Keywords having the number of characters less than the number entered here will be ignored.
Match type - Select Match any to have the search return items containing one or more keywords entered, or Match all to restrict search results to items containing all keywords entered.
Do not search post title - Whether to exclude post title from being searched.
Do not search post content - Whether to exclude post content (Listing Description field) from being searched.
Search child content items (requires Directories - Reviews) - Whether to match keywords against review title and content.
Search taxonomy term names - Whether to match keywords against category/tag/location term names.
Extra fields to include in search - Select custom fields that should be included in keyword search.
Note: Only the fields with field types that support keyword search (Single Line Text, Paragraph Text, Number, and Choice field types by default) are listed as options for this setting.
AUTO-SUGGEST SETTINGS
- Enable auto suggestions - Whether to display suggestions (listings, categories, tags, and/or locations) while typing into the keyword field.
FORM FIELD SETTINGS
Field icon - Select an icon to be displayed in the keyword search field.
Placeholder text - Default text to be displayed in the keyword search field when there are no keywords entered.
Display order - Display order of the keyword search field in the search form.
Location Search
The location search field lets users enter arbitrary text containing location information, such as a street address, a zip/postal code, a province name, etc. The field will use the geocoding API in the background for one or more latitude/longitude coordinates based on the location information entered, which are then used to match against location data of each listing in the directory.
Note: Make sure that a valid geocoding provider is configured in the Map settings (see Configure Map Libraries).
Hide this field - Whether to hide the location search field from the search form.
Default search radius - Limit listings in the search results to those within a certain search radius from the location entered in the location search field. Select Auto (recommended) to let the geocoding API calculate the optimal search radius.
Note: The reason Auto is recommended for this setting is that for example if a user enters a street name, you do not want the search radius 100km to be applied to the search since the user is most likely looking for listings in that street only and the user should certainly has no interest in listings 100km away from that street. If the default search radius is set to Auto, the geocoding API will take care of such issue and determine the optimal search radius based on the value entered in the location search field.
Enable search by user's current location - Whether to display the My current location option in the field. When the option is clicked, the system will try to locate the current address of the user and enter the address into the field if a valid address was fetched successfully.
Note: This setting is ignored if your site is not able to send/receive user data under the secure context (HTTPS) due to browser security restrictions.
AUTO-SUGGEST SETTINGS
Autosuggest terms - Whether to auto-suggest location taxonomy terms.
Depth of term hierarchy tree (0 for unlimited) - Specify the maximum depth of the location hierarchy from which auto-suggested location terms will be fetched. Enter 0 for unlimited depth.
Hide if no posts - Whether to hide location taxonomy terms without any posts from the auto-suggest list.
Hide post counts - Whether to hide post count numbers of auto-suggested location taxonomy terms.
Include parent term paths in term title - Whether to display the hierarchy path of parent location terms (e.g., U.S.A. -> New York -> Albany) for each auto-suggested location term.
FORM FIELD SETTINGS
Field icon - Select an icon to be displayed in the location search field.
Placeholder text - Default text to be displayed in the location search field when there is no text entered in the field.
Display order - Display order of the location search field in the search form.
Location Selection Search
The location selection search field lets users select a location taxonomy term from a dropdown. Use this field instead of the Location Search field if you do not wish to have visitors enter random address but let them simply select one of the pre-defined location taxonomy terms in your directory.
Hide this field - Whether to hide the location selection search field from the search form.
Depth of term hierarchy tree (0 for unlimited) - Specify the maximum depth of the location hierarchy from which location terms will be fetched and displayed in the dropdown. Enter 0 for unlimited depth.
Hide empty terms - Whether to hide location taxonomy terms without any posts.
Hide post counts - Whether to hide post count numbers of location taxonomy terms.
FORM FIELD SETTINGS
- Display order - Display order of the location select search field in the search form.
Category Selection Search
The category selection search field lets users select a category taxonomy term from a select dropdown.
Hide this field - Whether to hide the category selection search field from the search form.
Depth of term hierarchy tree (0 for unlimited) - Specify the maximum depth of the category hierarchy from which category terms will be fetched and displayed in the dropdown. Enter 0 for unlimited depth.
Hide empty terms - Whether to hide category taxonomy terms without any posts.
Hide post counts - Whether to hide post count numbers of category taxonomy terms.
FORM FIELD SETTINGS
- Display order - Display order of the category selection search field in the search form.
Click Save Changes to save the settings.
Search form shortcode
The search form can also be displayed using the [drts-directory-search]
shortcode. By using the shortcode you can embed the search form to another WordPress page, a theme template file, or even in a sidebar widget.
The following is the list of parameters available with the shortcode:
directory (required) - Machine name of the directory the search form is for.
btn_text - Specify a custom text used for the search form button label, defaults to none.
btn_icon - Specify the name of a FontAwesome icon used for the search form button, defaults to fas fa-search.
btn_color - Specify the name of color scheme used for the search form, one of primary, secondary, success, warning, danger, info, dark, light, defaults to primary.
btn_safari_no_disable - Whether to NOT disable the search button on form submission when using Safari, 0 or 1, defaults to 0.
size - Size of the search form, either lg for large sized form or none, defaults to none.
style - Custom CSS styles applied to the search form, added as the style attribute to the <form> tag.
fields - Specify the fields to be displayed in the search form, using field names separated by a comma. This will override the Hide this field setting of each field. Valid field names are keyword, location_address, term_location_location, term_directory_category.
delay_show - Use this parameter to delay displaying of the search form until CSS files are fully loaded. Set the value to 1 or a numeric value larger than 1 to specify delay time in milliseconds.
responsive - Whether to make the search form responsive, -1 for non-responsive (inline), 0 for non-responsive (stacked), and 1 for responsive, defaults to 1.
Example:
[drts-directory-search directory="my_directory"]
The following is some sample output of the shortcode: