Published

Updated

Feature Highlight: The [gravityview] Shortcode

In this edition of Feature Highlights, we’re exploring the powerful [[gravityview]] shortcode. No, it’s not only for embedding Views! The [gravityiew] shortcode allows you to filter entries by specific values, display the total number of entries in a View, and much more. Shortcodes in...

In this edition of Feature Highlights, we’re exploring the powerful [[gravityview]] shortcode. No, it’s not only for embedding Views! The [gravityiew] shortcode allows you to filter entries by specific values, display the total number of entries in a View, and much more.

Shortcodes in WordPress are text strings enclosed in square brackets. They allow you to embed interactive content on your site without writing any code. GravityView adds several new shortcodes to WordPress including the [[gravityview]] shortcode which we’re going to explore in this post 👇

How to use the [gravityview] shortcode

You can find the [[gravityview]] shortcode on the View Editor page above the “Update” button. Here it’s referred to as the “Embed Shortcode”, but there’s a lot more you can do with it besides simply embedding Views.

The GravityView embed shortcode displayed on the View editor page

The shortcode only has one required parameter: the View ID. All other parameters are optional and can be used if/when you need them! 

Adding the shortcode in the WordPress block editor

If you use the WordPress block editor, the easiest route is the GravityView View block — search “GravityView” in the block inserter (or type /gravityview), pick your View, and configure it from the sidebar panel. GravityView ships five blocks in total covering Views, individual entries, entry fields, entry links, and View details.

Prefer to paste shortcode text verbatim? Use WordPress’s built-in Shortcode block and drop [gravityview id="24"] (with your View ID) inside it.

Important: If the View has Enable Enhanced Security turned on, the shortcode needs the secret attribute or it won’t render. The GravityView View block adds this automatically — the Shortcode block doesn’t.

Shortcode parameters

The [[gravityview]] shortcode accepts a wide range of parameters. Here are some of the common ones that you can use to filter your Views based on specific field values:

  • search_value – Only display entries that contain the specified value
  • search_field – Restrict the search_value to 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. The default is “contains”. Accepted values: is, isnot, in, not in, contains, starts_with, ends_with, like, greater_than, less_than, greater_than_or_is, less_than_or_is.
  • start_date – Filter the results by date. This sets a limit on the earliest results shown. 
  • end_date – This sets a limit on the latest results shown.
  • detail – Display specific information about a View. The detail parameter can be used inside a Custom Content field to display information about the currently-displayed View.

Pro tipThe bullet list above covers the parameters you’ll use most often. For the complete set (including sort_field and sort_direction, offset, detail, class, single_title, back_link_label, and the post_id / secret attributes) see Using the [gravityview] shortcode on the docs site.

Heads-up on search_operator. The accepted values in the current GravityView release are is, isnot, in, not in, contains, starts_with, ends_with, like, greater_than, less_than, greater_than_or_is, and less_than_or_is. Older notation like <> or >= isn’t current — if you’ve seen those elsewhere, use the values above instead.

Use Cases for the [gravityview] Shortcode

Reading through a list of different shortcode parameters is all well and good, but sometimes it helps to look at some examples of common use cases.

1. Embedding a View:

[gravityview id="24"]

2. Filtering a View to display entries that contain a certain value:

[gravityview id="24" search_value="Silver Member" search_field="4"]

3. Limiting entries by date created:

[gravityview id="24" start_date="2021-10-01" end_date="2021-10-31"]

4. Displaying the total number of entries in a View:

[gravityview id="10" detail="total_entries"]

Pro tipYou can use a [[gravityview]] shortcode with the detail parameter inside a custom content field to display information about the View being displayed.

There are plenty more use cases for the [[gravityview]] shortcode. To see more examples of things you can do, check out our documentation.

What the [gravityview] Shortcode CAN’T Do

We’ve focused a lot on what the [[gravityview]] shortcode CAN do (and it can do a lot of things!), but it’s also important for us to mention what it CAN’T do.

While [[gravityview]] includes some powerful filtering capabilities, there are some limitations. For example, you can’t search for multiple values or specify multiple search fields. You also cannot use AND/OR logic in searches. 

However, if you need this functionality, don’t despair, because you can accomplish this with our Advanced Filtering extension.

Get Started With the [gravityview] Shortcode!

In this edition of Feature Highlights, we explored the powerful [[gravityview]] shortcode. Using the shortcode, you can embed Views, filter entries based on various criteria and display specific details about a particular View.

To learn more about the [[gravityview]] shortcode, read the article on our docs site, or watch the tutorial video on our YouTube channel. For more helpful hints and tips subscribe to our blog below!