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 index page.

Follow these steps to enable search for your directory:

  1. Login to your website if not yet logged in and go to the WordPress administration dashboard.

  2. Click Directories in the admin sidebar.

  3. Under the All Directories tab, click the gear icon in the row of the directory to edit.

  4. Under the Settings tab, scroll down the page and select Yes for Enable search.

  5. 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 index page. For example if your directory index page is http://example.com/directory, the search form can be viewed at http://example.com/directory/search.

Follow the steps below to configure and customize the search form for your directory.

  1. Login to your website if not yet logged in and go to the WordPress administration dashboard.

  2. Click Directories in the admin sidebar.

  3. Under the All Directories tab, click the gear icon in the row of the directory to edit.

  4. Under the Content Types tab, click the Edit button in the Listing row.

  5. 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 or not 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.

      • Default 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.

      • Search child content items (requires Directories - Reviews) - Whether or not to match keywords against review title and content.

      • Search taxonomy term names - Whether or not 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 or not 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 query Google using Google Maps 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 Google Maps API is configured to use this field. See Installation - Setting Up Google Maps API for details on setting up the API.

      • Hide this field - Whether or not to hide the location search field from the search form.

      • Google Place Autocomplete - Place type - Select the type of auto-suggested location information returned by Google Maps Places API.

      • Google Place Autocomplete - Country code - Enter one of the two-letter country codes (http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) to restrict auto-suggestions returned by Google Maps Places API to a specific country.

      • 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 Google Maps 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, Google 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 or not 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 or not 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 or not to hide location taxonomy terms without any posts from the auto-suggest list.

        • Hide post counts - Whether or not to hide post count numbers of auto-suggested location taxonomy terms.

        • Include parent term paths in term title - Whether or not 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 or not 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 or not to hide location taxonomy terms without any posts.

      • Hide post counts - Whether or not 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 or not 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 or not to hide category taxonomy terms without any posts.

      • Hide post counts - Whether or not 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.
  6. 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.

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

Example:

[drts-directory-search directory="my_directory"]

The following is some sample output of the shortcode:

results matching ""

    No results matching ""