Using the [gravityview] shortcode
The [gravityview] shortcode embeds a View on a page, a post, a sidebar widget, or inside another View. Its parameters filter and limit the entries the View shows.
Tutorial video #
This video walks through the most common uses of the [gravityview] shortcode:
Common use cases #
Most uses of the [gravityview] shortcode display a View, filter its entries, or change their order.
Displaying a View
To display a View, all you need is the View ID:
[gravityview id="24"]Displaying entries that contain a specific value
[gravityview id="24" search_value="Silver Member" search_field="4"]This lists the entries whose field 4 contains “Silver Member.” The search_value parameter sets the value to look for, and search_field limits the search to one form field.
Watch the beginning of the tutorial video above for guidance on finding the ID of a specific form field in Gravity Forms.
Limiting entries by date created
[gravityview id="24" start_date="2021-10-01" end_date="2021-10-31"]The date should be written using the yyyy-mm-dd format. Alternatively, you can use relative dates like this:
[gravityview id="24" start_date="-1month" end_date="today"]Advanced use cases #
Filtering a View with a search operator
The search_operator parameter changes how search_value is compared. For example, this lists the entries whose field 4 isn’t “baseball”:
[gravityview id="24" search_field="4" search_value="baseball" search_operator="isnot"]The search_operator parameter accepts is, isnot, <> (the same as isnot), contains, like, starts_with, ends_with, in, not in, >, <, >=, and <=. Any other value is treated as contains. For in and not in, separate the values with commas, such as search_value="Sales, Support". With like, % stands for any text, as in search_value="Sa%". With isnot, the whole value is compared, so an entry holding “Baseball team” is still listed. Use isnot together with search_field: without it, an entry is listed when any of its fields differs from the value, which is nearly every entry.
Operators other than is, isnot, contains, >, and < need GravityView 3.8.0 or newer.
Displaying the total number of approved entries
GravityView’s approval system lets you approve entries before they show in a View. To display the number of approved entries, use the detail parameter (described below) with search_field="is_approved".
[gravityview id="100" detail="total_entries" search_field="is_approved" search_value="1"]Displaying the number of disapproved or unapproved entries is also possible by changing the search value (search_value="2" or search_value="3").
Displaying entries created by a specific user
[gravityview id="42602" search_field="created_by" search_operator="is" search_value="8"]This example searches the created_by field for the user with ID 8.
Displaying entries created by the logged-in user
[gravityview id="42602" search_field="created_by" search_operator="is" search_value="{user:ID}"]The {user:ID} merge tag shows the ID of the logged-in user. Logged-out visitors see no entries. Showing user details with the {created_by} and {user} merge tags explains the {user} merge tag.
Displaying details about a View #
The detail parameter shows information about a View. Use it inside a Custom Content field to show details of the View that field belongs to. This shortcode is available as a block.
Displaying the total number of entries in a View
[gravityview id="10" detail="total_entries"]This shows the number of entries in the View across all its pages.
Displaying the number of entries visible on a single page
To display the number of entries visible on the page, use the page_size value:
[gravityview detail="page_size"]Displaying the number of the first or last entry
The first_entry and last_entry details show the number of the first and last entry. When the View is embedded on a page or post, add its ID:
[gravityview id="8" detail="first_entry"]You could also display the number of the last entry:
[gravityview id="8" detail="last_entry"]All shortcode parameters #
These are the main [gravityview] shortcode parameters:
Required:
id: The ID of the View to display.
Security:
secret: The secret GravityView creates for the View when the setting is on. Enable Enhanced Security: the secret attribute for shortcodes explains the setting.
For example, add secret="your-view-secret" to the shortcode after the View ID, with the View’s own secret in place of your-view-secret.
Searching/filtering:
search_value: Only shows entries that contain the value.search_field: Limitssearch_valueto one form field. The value must be the field ID, unless you’re searching a meta field such ascreated_by.search_value_empty: What to show whensearch_valueis a merge tag that comes out empty, such as{get:customer}on a page address with nocustomerparameter:noneshows no entries, andallshows every entry. Without it, every entry is shown and administrators see a notice naming the page. Requires GravityView 3.8.0 or newer.search_operator: Changes how the value is compared. The default iscontains. Accepted values:is,isnot,<>(the same asisnot),contains,like,starts_with,ends_with,in,not in,>(greater than),<(less than),>=(greater than or equal to), and<=(less than or equal to). Any other value is treated ascontains.start_date: Filters the results by date. It sets the earliest date shown. Write dates inYYYY-MM-DDformat, or use relative dates.end_date: Filters the results by date. It sets the latest date shown. Write dates inYYYY-MM-DDformat, or use relative dates.
Other:
post_id: The ID of the page where the View is embedded. Entry links use that page as their base URL, which helps when the shortcode is in a widget or template.detail: Shows a detail about the View, as described above.class: Adds an HTML class to the View’s wrapper.single_title: A custom title for the Single Entry page. Default: the post or page title.back_link_label: A custom label for the link back from the Single Entry page. Default:← Go back.page_size: The number of entries shown at a time. Without it, the View uses the value in its View Settings. Use-1to show all entries.offset: The number of entries to skip. Withoffset="12", the View starts at the 13th entry.
Shortcode limitations #
The shortcode searches for one value in one field at a time, with no AND or OR logic. To filter by several values or fields, use the Advanced Filtering extension.