Using the [gravityview] Shortcode
The [gravityview] shortcode allows you to embed Views on your website. But that’s not all. There is also a range of parameters you can use to customize the output.
You can use the [gravityview] shortcode on pages, posts, sidebar widgets, or even inside other Views. The [gravityview] shortcode is powerful and you can use it to achieve a number of different outcomes, both simple and complex.
- Tutorial Video
- Common Use-Cases
- Advanced Use-Cases
- Displaying Details About a View
- All Shortcode Parameters
- Shortcode Limitations
Tutorial Video #
Here is a quick tutorial video guiding you through some of the most common uses-cases for the [gravityview] shortcode:
Common Use-Cases #
The most common use cases for the [gravityview] shortcode usually centers around displaying Views, filtering entries based on certain conditions, and modifying the entry order.
Here are some of the most common use cases:
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 will show all entries that include the word โSilver Memberโ. The search_value parameter allows you to specify a search value, and the search_field parameter restricts the search to a specific form field.
Watch the beginning of the tutorial video above for guidance on finding the ID of a specific form field in Gravity Forms.
Changing the Sort Direction of a View:
[gravityview id="24" sort_direction="ASC" sort_field="4"]You can change the sort direction by specifying ASC , DESC , or RAND . The sort_field parameter is required in the form of a field ID when using thesort_direction parameter.
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 #
The [gravityview] shortcode can also be used for more advanced use cases. Here are some examples:
Filtering a View Using Advanced Search:
The search_operator parameter allows you to perform more advanced searches using different filters. For example, hereโs how you would display all entries that do not contain the word โBaseballโ.
[gravityview id="24" search_value="baseball" search_operator="isnot"]The search_operator parameter accepts the following values: is , isnot , like , in , contains , starts_with , ends_with , like .
So, for example, if you wanted to display entries where the โemail addressโ field (with an ID of โ4โ) ends with โ@gravityview.coโ, you could use the following shortcode:
[gravityview id="24" search_value="@gravityview.co" search_field="4" search_operator="ends_with"]Displaying the total number of approved entries:
GravityViewโs approval system allows you to manually approve entries before they show up inside a View. To display the number of approved entries, you can use the detail parameter (more on this below) along 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 (i.e. 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"]In this example, weโre searching on the “created_by” field and setting the search_value equal to the user ID (in this case, โ8โ).
Displaying Entries Created by the Currently Logged-In User:
[gravityview id="42602" search_field="created_by" search_operator="is" search_value="{user:ID}"]The {user:ID} Merge Tag will automatically pull the ID of the currently logged-in user. More about the {user} Merge Tag.
Displaying Details About a View #
The detail parameter can be used inside a Custom Content field to display information about the currently-displayed View. This shortcode is available as a block.
Displaying the total number of entries in a View:
[gravityview id="10" detail="total_entries"]This will display the total number of entries in the View (i.e. all entries,ย not just the entries displayed).
Displaying the number of entries visible on a single page:
If you only want to display the number of entries visible on the page, you can use the “page_size” value:
[gravityview detail="page_size"]Displaying the number of the first or last entry:
You can also display the number of the first or last entry displayed on a page. If your View is embedded on a page or post, youโll need to specify the View ID as a shortcode parameter:
[gravityview id="8" detail="first_entry"]Letโs say you have a View displaying entries 26-50 of a total of 100 entries. In this case, the output would be โ26โ.ย
You could also display the number of the last entry:
[gravityview id="8" detail="last_entry"]In this case, the output would be โ50โ.
All Shortcode Parameters #
Here is an exhaustive list of all the available [gravityview] shortcode parameters:
Required:
id– The ID of the View you want to displayย
Security:
secret– The secret automatically generated for the specific View if the setting has been enabled. More about this setting here: Enable Enhanced Security: the secret attribute for shortcodes
Example:
[gravityview id="776" secret="d4e8bad831bb"]Searching/filtering:
search_value– Only display entries that contain the specified valuesearch_field– Restrict thesearch_valueto a specific form field. The value must be the field ID, unless youโre searching on a meta field (e.g. โcreated_byโ).search_operator– Change the type of search to be performed. Default is “contains”. Accepted values include:isisnotnot iningreater_thanless_thangreater_than_or_isless_than_or_iscontainsstarts_withends_withlike
start_date– Filter the results by date. This sets a limit on the earliest results shown. Dates should be written inYYYY-MM-DDformat. You can also use relative dates.end_date– Filter the results by date. This sets a limit on the latest results shown. Dates should be written inYYYY-MM-DDformat. You can also use relative dates.
Sorting:
sort_direction– Defines how entries should be sorted. Accepted values are โASCโ (for ascending) or โDESCโ (for descending), ‘RAND’ (for random).sort_field– The form field that should be used to sort. The value must be a field ID.ย
Other:
post_id– When using the shortcode in a widget or template, you may want to specify a page where a View is embedded as the base URL for entry links. Default: NULL.detail– Display specific information about a View (explained above).class– Add an HTML class to the view wrapper.single_title– Define a custom Single Entry page title (default: post/page title).back_link_label– Define a custom title for the Single Entry โGo backโ link (default: โโ Go backโ).page_size– Defines the number of entries to display at a time. If no value is set, this will default to the value set in your View Settings. Use-1to show all entries.offset– Defines the starting point of the View (i.e. setting the value to โ12โ means the View will display entries beginning with entry number 12).
Shortcode Limitations #
While the [gravityview] shortcode is suitable for a range of different use cases, it does have some limitations that you should be aware of.
For example, itโs not possible to search for multiple values or specify multiple search fields. Itโs also not possible to use AND/OR logic in searches. For this functionality, youโll need our Advanced Filtering extension.