-
Notifications
You must be signed in to change notification settings - Fork 62
[gventry]
The [gventry]
shortcode allows you to embed a GravityView Entry in a post, page, or in another View's Custom Content field.
This is a WordPress shortcode. It can be used in post content by adding [gventry]
(+ parameters) and in PHP code by calling do_shortcode
. The parameters:
parameter | values | description |
---|---|---|
id required |
$id, "last", "first" | A numeric ID or slug referencing the entry. Or the last, first entry from the View. The View's sorting and filtering settings will be applied to the entries. Required. |
view_id |
$id | The numeric View ID the entry should be displayed from. Required. |
Show the most recent entry from View ID #4 (which is sorted to show the most recent entry first):
[gventry entry_id="first" view_id="4"]
The standard security rules to outputting fields apply. In short, an entry will not be shown if the current user cannot see the entry in the context of the View. Unapproved entries? A no show to non-admins. In Trash? Nope. If the View is password protected, a draft, or private? No way!
The [gvfield]
shortcode calls upon several filters that allow developers to modify the output as needed.
Filter the final output value of the Entry about to be rendered. Useful to override empty entries; for example, for non-logged in users, this can be used to output the registration link instead of a blank profile link.
add_filter( 'gravityview/shortcodes/gventry/output', function( $output, $view, $entry, $atts ) {
if ( $view && $view->ID === MY_SECRET_VIEW ) {
if ( ! is_user_logged_in() ) {
return '<a href="#">Login</a>';
}
}
return $output;
}, 10, 4 );
Filter the initial shortcode attributes. Useful to tack on defaults or dynamically change IDs, etc.
add_filter( 'gravityview/shortcodes/gventry/atts', function( $atts ) {
if ( $atts['view_id'] == MY_SECRET_VIEW && $user = wp_get_current_user() ) {
$atts['id'] = $user->secret_entry_id;
}
return $atts;
} );