Using the [gvfield] shortcode to embed single field values
The [gvfield] shortcode shows one field’s value from one entry of a View, anywhere a shortcode works. For example, this shows the member name from the last entry View 12 lists:
[gvfield view_id="12" entry_id="last" field_id="1"]Parameters #
view_id(required): the ID of the View the entry comes from.entry_id(required): an entry ID, orfirstorlastfor the first or last entry the View lists, in the View’s sort order. Merge tags work here, such as{get:member}to take the ID from the page address.field_id(required): one field ID from the View’s form, or one of these entry details:date_created,id,created_by,entry_linkandedit_link. To show several fields, use one shortcode per field.secret: the View’s secret, needed when the View has Enable Enhanced Security on. Enable Enhanced Security: the secret attribute for shortcodes explains the setting.- Any other attribute sets that field setting for this shortcode, such as
choice_displayorentry_link_text, as in the examples below.
Examples #
Showing the newest entry’s value
In a View sorted by entry ID in ascending order, the default, last is the newest entry:
Our newest member is [gvfield view_id="12" entry_id="last" field_id="1"], who joined on [gvfield view_id="12" entry_id="last" field_id="date_created"].On the page, this reads “Our newest member is Isabel Rocha, who joined on October 22, 2026.”
Taking the entry from the page address
With entry_id="{get:member}", the page address picks the entry, so /members/?member=1134 shows the name from entry 1134:
[gvfield view_id="12" entry_id="{get:member}" field_id="1"]Showing the label or the value of a choice
For a field whose choices have values that differ from their labels, choice_display picks what shows: label shows the choice’s label, and value its value. Without it, the value shows.
[gvfield view_id="12" entry_id="first" field_id="7" choice_display="label"]
[gvfield view_id="12" entry_id="first" field_id="7" choice_display="value"]For a choice labeled “By phone” with the value phone, the first line shows By phone and the second phone.
Linking to the entry and to Edit Entry
field_id="entry_link" shows a link to the entry’s single entry page on the current page, and entry_link_text sets the link text. field_id="edit_link" shows a link to edit the entry to users who can edit it, and the edit_link attribute sets its text.
[gvfield view_id="12" entry_id="1137" field_id="entry_link" entry_link_text="Open profile"]
[gvfield view_id="12" entry_id="1137" field_id="edit_link" edit_link="Edit my profile"]Who sees the value #
- The entry must be one the View lists. An entry the View’s filters leave out, such as an unapproved entry in a View that shows only approved entries, shows nothing, also to administrators.
- On a View with Enable Enhanced Security on, add
secret. Without it, visitors see nothing and administrators see a notice with the secret to add. - A View that isn’t published, such as a draft, shows nothing to visitors. Administrators still see the value.
- A password-protected View shows its password form in place of the value.
- The shortcode works with a View that has Prevent Direct Access on.
Changing the output with filters #
The gravityview/shortcodes/gvfield/output filter changes what the shortcode prints, and gravityview/shortcodes/gvfield/atts changes its attributes before it runs.
gravityview/shortcodes/gvfield/output
This prints a log-in link for logged-out visitors where View 12 prints nothing, such as an edit_link field they can’t use:
add_filter( 'gravityview/shortcodes/gvfield/output', function ( $output, $view, $entry, $field ) {
// Logged-out visitors see a log-in link where View 12 prints nothing.
if ( '' === $output && $view && 12 === (int) $view->ID && ! is_user_logged_in() ) {
return '<a href="' . esc_url( wp_login_url( get_permalink() ) ) . '">Log in to edit your profile</a>';
}
return $output;
}, 10, 4 );gravityview/shortcodes/gvfield/atts
This makes a [gvfield] without entry_id show the View’s last entry:
add_filter( 'gravityview/shortcodes/gvfield/atts', function ( $atts ) {
// A [gvfield] without an entry_id shows the View's last entry.
if ( empty( $atts['entry_id'] ) ) {
$atts['entry_id'] = 'last';
}
return $atts;
} );Note: Adding custom PHP code snippets to your website explains where to add this code.