BrightLeaf Digital Code Snippet Library

Check out our growing library of code snippets for Gravity Forms!

GFSearch Shortcode

GFSearch

A powerful and flexible Gravity Forms search and display shortcode for WordPress.

📝 Description

The GFSearch shortcode enables advanced searching and displaying of Gravity Forms entries on your posts, pages,
Gravity Views, or custom templates. It functions similarly to an Excel VLOOKUP, allows filtering results, sorting entries, custom formatting, and much more—all
tailored to your exact needs.

✨ Key Features

  • Form Targeting: Search entries across all forms, specific forms, or selected forms via IDs.
  • Field Filtering: Search or display multiple fields simultaneously using field IDs and corresponding values.
  • Custom Formatting: Customize output using placeholders and HTML formatting, supporting field data and meta-properties.
  • Sorting Options: Primary and secondary sorting by ascending, descending, or random order.
  • Comparison Filters: Filter numeric fields by values (greater than or less than).
  • Global Search: Search all form fields for specific values easily.
  • Unique Results: Eliminate duplicate entries by enabling the unique option.
  • Advanced Search Modes: Match any condition (search_mode="any") or all conditions (default).
  • HTML Supported in Display: Fully supports HTML in display and separator attributes, e.g., <li> for lists.
  • Search for Empty Fields: Identify and display entries with missing field data.
  • Entry Linking: Convert results into links to entry admin panel views.

🚀 Usage

To use the shortcode, embed in your content areas with relevant attributes, e.g.: [gfsearch]

[gfsearch target="1" display="13"]

This displays the value of field ID 13 from the latest entry in form 1.

Attributes Overview

Attribute Description Default
target Specify forms to search: 0 for all forms, or comma-separated list of form IDs (e.g., target="1,2"). (all forms) 0
search Field IDs/entry properties for filtering entries. Separate multiple IDs by a comma (search="13,14"). The corresponding values to search for should be placed in the shortcode content, separated by the pipe operator. (None)
operators Comma-separated list of operators that correspond to each field in the search attribute. See documentation below for a list of supported operators. (None)
display Comma separated list of field IDs/entry properties to display. Also allows formating results with placeholders. (Required)
search_mode Match all conditions (all, default) or any condition (any). all
sort_key Field/property to sort entries (e.g., field ID or meta key). id (entry ID)
sort_direction Sorting direction: ASCDESC, or RAND. DESC
sort_is_num Indicates if sorting is numeric (true/false). true
secondary_sort_key Secondary sorting field (if needed). (empty)
secondary_sort_direction Sorting direction for the secondary sort (ASC, DESC). DESC
unique Display only unique values in the results. false
limit Number of results to display. Use limit="all" to display all entries. 1
separator Separator between entry results (supports HTML). Will only be used when there is more than one entry returned by the search. To configure a blank separator, enter __none__. (Varies)
search_empty Search for fields with empty/blank values. false
default Default text to display if no results match search criteria. Can input multiple values corresponding to each display value, separated by a double pipe symbol. (Blank)
link Makes results clickable links to admin entry details. false

🧩 Examples

Example 1: Display fields 16 and 17 (comma separated) when field 13 matches John and 14 matches john@example.com

This will display the results from the five latest matching entries from form 1. The entry results will be each on a new line.
The shortcode will return 'No results found' for any blank entries or blank results in matching entries.

[gfsearch target="1" search="13,14" display="16, 17" limit="5" separator="<br>" default="No results found"]
John|john@example.com
[/gfsearch]

Example 2: Search and Display Multiple Fields

[gfsearch target="2" search="13,14" display="Name: {13}, Email: {14}" search_mode="all" limit="10"]
John|john@example.com
[/gfsearch]

This will return a list of unique created_by values from form 3. Each will link to its corresponding admin entry view.

[gfsearch target="3" display="Unique Entry: {created_by}" unique="true" link="true"]

Example 4: Global Search with Custom HTML

This searches across all forms and fields and creates an HTML list showing the entry ID and the value of field 13.

[gfsearch target="0" display="<li>ID: {id}, Value: {13}</li>" separator="__none__"]

Wrap the above shortcode within <ul> tags:

<ul>
    [gfsearch target="0" display="<li>ID: {id}, Value: {13}</li>" separator="__none__"]
</ul>
  <table>
    <thead>
      <tr><th>Name</th><th>Email</th><th>Link</th></tr>
    </thead>
    <tbody>
    [gfsearch target="1" search="3,5" display="<tr><td>{1}</td><td><a href='mailto:{2}'>{2}</a></td><td><a href='{6}&query={10}'>{6}&query={10}</a></td></tr>" separator="__none__"]
    John Doe | john@example.com
    [/gfsearch]
    </tbody>
  </table>

You can create links to anywhere you want, including other views or parts of this view!

Example 6: Secondary Sort

  [gfsearch target="2" display="13" sort_key="date_created" secondary_sort_key="name" secondary_sort_direction="ASC"]

🖼️ Display Attribute

The display attribute controls what is shown for each matching entry. You can use it in two different formats, comma-separated field list and a custom display string. Read more about the GFSearch display attribute.

🧬 Nested Shortcodes

You can include shortcodes inside the display attribute using double curly braces ({{ ... }} syntax). This allows you to embed other shortcodes—like gravitymathgfsearch or any other shortcode—within the output for each entry. Read more about nesting shortcodes in GFSearch.

⚖️ Operators Attribute

The operators attribute allows you to define how each search value is compared to its corresponding field in the search attribute. It should be a comma-separated list, with each operator matching its position to the same-positioned field ID in the search attribute. Read more about using operators with GFSearch.

❗ Notes and Best Practices

  • To search multiple fields pass comma separated IDs to the search attribute and separate the corresponding values in
    the shortcode content with the | symbol. Use the search_mode attribute to configure if any or all conditions must
    match. To search for multiple values for the same field, repeat the field ID in the search attribute with the corresponding values in the shortcode content.
  • Custom Formatting: Use the display attribute with placeholders, enabling displays in a complex format.
    You can create lists or tables, link to entries in a Gravity View, create mailto links, the possibilities are almost
    endless! You can define CSS classes allowing for even more customization! See above for details.
  • The search and display attributes both support entry properties and field IDs. See Gravity Forms Entry Object.
  • To perform a global search for any field with a specified value, leave the corresponding search ID blank.
  • To display values from a field without searching, omit the search attribute and shortcode content.
  • Sorting:
    Use sort_key (field ID, entry property, or entry meta key), sort_direction (ASCDESC (default), RAND),
    and sort_is_num (true/false). For secondary sorting, use secondary_sort_key and secondary_sort_direction.
    Secondary sorting is ignored if primary sort direction is RAND.
    Please note that dates are numeric regarding the sort_is_num attribute.
  • Use the unique attribute with any non-empty value to return only unique results. Please Note: that if the results
    are not exactly the same they will be treated as unique. So the results example.com and example.con as a typo
    will be considered unique.
  • To search for empty values, leave the shortcode content blank and use the search_empty attribute with any non-empty value.
  • Use the default attribute to specify a value to display when no results are found or for blank values within entries.
  • Use the link attribute with any non-empty value to wrap each result in a link to the entry view page in the WordPress admin.
  • When using the shortcode content to pass in search values (separated by the | character), avoid using the pipe (|)
    symbol inside the actual values themselves. Escaping is not currently supported, so including a pipe within a value may
    result in incorrect or partial matches.
  • The [gfsearch] shortcode does not restrict access by default. Anyone who can view the page can see the search results, including Gravity Forms entry data.
    To protect sensitive information, place the shortcode inside pages with appropriate access controls (e.g., membership plugins, password protection, or role-based visibility).
  • Each [gfsearch] shortcode runs a live database query. Using many shortcodes, large forms, or limit="all" can slow down page loads.
    To improve speed:

    • Use limit to cap results
    • Minimize nested shortcodes
    • Consider caching the page output
  • If there are more search IDs than values, extra fields will search for blank entries. Extra values beyond the number of IDs are ignored.

🧩 Multi-Input Field Support

Multi-input fields—such as NameAddress, and Checkbox fields—contain multiple inputs within a single field.
This snippet supports both displaying and searching these fields, but the behavior differs slightly between display and search. Read more about multi-input field support with GFSearch.

Installation

This shortcode can be installed as a snippet or as a plugin.

As a Plugin

Download the zip and install in the WP admin dashboard.

As a snippet

Copy the code from here
and install in your themes functions.php file or with your favorite code snippets plugin.

📜 License

This plugin is licensed under GPLv2 or later.

Install Using Code Snippets

This code is best installed directly on your site using the Code Snippets plugin.

Check Out the Code

Loading...

Code Copied!
Stay Updated On This Snippet

One review of this entry No Rating