BrightLeaf Digital Code Snippet Library

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

GFSearch Shortcode

The GFSearch Shortcode snippet allows you to search Gravity Forms entries dynamically and retrieve specific field values using a simple shortcode. It functions similarly to an Excel VLOOKUP, enabling users to search by field values and display results with custom formatting and sorting.

This shortcode is highly customizable, supporting complex search queries, conditional filtering, sorting, and unique value retrieval. It is ideal for displaying form data dynamically on the front end without writing custom queries or using the Gravity Forms API manually.


Features

  • Search Gravity Forms entries dynamically based on specified field values.
  • Supports multiple forms by searching all forms or specific form IDs.
  • Allows multiple search and display fields using comma-separated values.
  • Customizable formatting for display results using {field_id} placeholders.
  • Flexible sorting options, including primary and secondary sorting.
  • Filters entries based on greater-than or less-than conditions.
  • Supports retrieving unique values by eliminating duplicates.
  • Adjustable limit on the number of results returned (all or a specific number).
  • Case-insensitive and numeric-aware sorting for accurate data retrieval.
  • Ability to search for empty field values with the search_empty attribute.
  • Supports limited HTML formatting in results (e.g., <br> for line breaks).

Configuration Guide

Basic Usage

Use the shortcode [gfsearch] with the appropriate attributes to retrieve and display data from Gravity Forms entries.

Example: Basic Search and Display
[gfsearch target="10" search="5" display="7"]John Doe[/gfsearch]

This searches Form ID 10 for entries where Field ID 5 equals "John Doe" and displays the value of Field ID 7.


Shortcode Attributes

Below are the available attributes and how to use them:

Attribute Default Description
target 0 Form ID(s) to search (0 = all forms, or comma-separated list of IDs).
search (empty) Field ID(s) to search. Comma-separated for multiple fields.
display (empty) Field ID(s) to display. Comma-separated for multiple fields.
greater_than false Filter results where a field value is greater than the given number (format: field_id, value).
less_than false Filter results where a field value is less than the given number (format: field_id, value).
sort_key id Field ID or entry meta key used for sorting.
sort_direction DESC Sorting direction (ASC, DESC, RAND).
sort_is_num true Indicates if sorting is numeric (true/false).
secondary_sort_key (empty) Secondary sorting field (if needed).
secondary_sort_direction DESC Sorting direction for the secondary sort (ASC, DESC).
unique false Ensures only unique values are returned.
limit 1 Number of results to return (all for unlimited).
search_mode all Determines if all search conditions must be met (all) or if any match is enough (any).
separator (empty) Separator between results (e.g., <br>).
search_empty false Allows searching for empty field values.

Advanced Usage

1. Searching Multiple Fields
[gfsearch target="12" search="5,6" display="7"]John|Doe[/gfsearch]
  • Searches Form ID 12 where Field ID 5 = "John" and Field ID 6 = "Doe".
  • Displays Field ID 7.
2. Custom Formatting
[gfsearch target="10" search="5" display="Customer: {7}, Order: {8}"]John Doe[/gfsearch]
  • Displays: "Customer: [value of Field 7], Order: [value of Field 8]".
3. Sorting and Filtering
[gfsearch target="15" search="10" display="12" sort_key="14" sort_direction="ASC" limit="5"]100[/gfsearch]
  • Searches Form ID 15 where Field ID 10 = "100".
  • Displays Field ID 12, sorted by Field ID 14 (Ascending Order).
  • Returns up to 5 results.
4. Searching for Empty Values
[gfsearch target="8" search="4" display="9" search_empty="true"][/gfsearch]
  • Finds entries where Field ID 4 is empty and displays Field ID 9.
5. Using Greater Than / Less Than Conditions
[gfsearch target="22" greater_than="5, 50" display="7"][/gfsearch]
  • Retrieves Field ID 7 where Field ID 5 is greater than 50.
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