Adding Search

The search feature lets you set up a basic search form for your directory.

If you have already set up filters for your directory by following the instructions in Adding and Managing Filters, you may not feel the need to set up another interface for finding listings. However, if there are a large number of filters, providing a basic search form as the initial entry point to your directory can greatly improve user experience. 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.

Follow these steps to enable search for your directory:

  1. Log in to your website if you are not already 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 you want to edit.

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

  5. Scroll down and click Save Changes.

By default, you can view the search form for 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 main page, you will need to use the following URL: http://example.com/directory?drts_action=search.

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

  1. Log in to your website if you are not already 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 you want 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.

  6. Keyword Search

    The keyword search field lets visitors enter keywords that are matched against field values of listings in the directory. By default, only values of the listing title and description fields are matched, but 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 shorter than the number entered here will be ignored.

    • Match type – Select Match any to return items containing one or more keywords entered, or Match all to restrict 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 to include in keyword search.

      Note: Only fields with 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 display in the keyword search field.

      • Placeholder text – Default text to display in the keyword search field when no keywords are entered.

      • Display order – Display order of the keyword search field in the search form.

  7. Location Search

    The location search field lets users enter arbitrary text containing location information, such as a street address, zip/postal code, province name, etc. The field uses the geocoding API in the background to obtain 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 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 radius from the location entered. Select Auto (recommended) to let the geocoding API calculate the optimal search radius.

      Note: Auto is recommended because, for example, if a user enters a street name, you do not want a search radius of 100km to be applied, since the user is most likely looking for listings on that street only. If the default search radius is set to Auto, the geocoding API will determine the optimal search radius based on the value entered.

    • Enable search by user's current location – Whether to display the My current location option in the field. When clicked, the system will try to locate the user's current address and enter it into the field if successful.

      Note: This setting is ignored if your site cannot send/receive user data under a 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 display in the location search field.

      • Placeholder text – Default text to display in the location search field when no text is entered.

      • Display order – Display order of the location search field in the search form.

  8. 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 want visitors to enter random addresses but want them to 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 selection search field in the search form.
  9. Category Selection Search

    The category selection search field lets users select a category taxonomy term from a 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.
  10. 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 into another WordPress page, a theme template file, or even a sidebar widget.

Below is a list of parameters available for the shortcode:

  • directory (required) – Machine name of the directory the search form is for.

  • btn_text – Specify custom text 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 color scheme used for the search form: 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: lg for large 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 display in the search form, using field names separated by commas. 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 the search form until CSS files are fully loaded. Set the value to 1 or a numeric value larger than 1 to specify the 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.

  • filter – Whether to show a filter form in the next step to allow the user to narrow the search results. 0 or 1, defaults to 0.

Example:

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

The following is some sample output of the shortcode:

results matching ""

    No results matching ""