Retrieve Entry Approval Status in GravityView
To get an entry’s approval status in code, use GravityView_Entry_Approval::get_entry_status(). It returns the label by default, such as Approved, or the value, such as 1. The status is stored in the entry meta under the key is_approved.
Read the status #
The method takes an entry ID or an entry array. Replace the example values in these samples with your own.
$entry_id = 456; // Replace 456 with your entry ID.
// The label: "Approved", "Disapproved", or "Unapproved".
$label = GravityView_Entry_Approval::get_entry_status( $entry_id );
// The value: 1, 2, or 3.
$value = GravityView_Entry_Approval::get_entry_status( $entry_id, 'value' );Note: Not sure where to add this code? See Adding custom PHP code snippets to your website.
Status values #
The values are constants on GravityView_Entry_Approval_Status, such as GravityView_Entry_Approval_Status::APPROVED:
| Constant | Value | Label | Meaning |
|---|---|---|---|
APPROVED | 1 | Approved | The entry has been approved. |
DISAPPROVED | 2 | Disapproved | The entry has been disapproved. |
UNAPPROVED | 3 | Unapproved | The entry hasn’t been approved or disapproved yet, or its approval was reset. |
Check a status #
The helper methods take a status value. Passing them an entry array returns false and raises a PHP warning, so read the value first:
$entry_id = 456; // Replace 456 with your entry ID.
$status = GravityView_Entry_Approval::get_entry_status( $entry_id, 'value' );
if ( GravityView_Entry_Approval_Status::is_approved( $status ) ) {
// The entry is approved.
}
if ( GravityView_Entry_Approval_Status::is_disapproved( $status ) ) {
// The entry is disapproved.
}
if ( GravityView_Entry_Approval_Status::is_unapproved( $status ) ) {
// The entry is unapproved.
}Note: Not sure where to add this code? See Adding custom PHP code snippets to your website.
Where the status is stored #
The status lives in the wp_gf_entry_meta table, with the meta_key is_approved and a meta_value of 1, 2, or 3. The status column of wp_gf_entry is a different thing: it holds the Gravity Forms entry status, such as active.
An entry that never went through a form submission, such as one made with GFAPI::add_entry(), can have no is_approved row. GravityView treats it as Unapproved, so a query for entries that aren’t approved has to include those.
Count entries with PHP
This gives the count a visitor sees on a View with Show only approved entries on and no other filters. Administrators and Editors see more on that View when Show all entries to administrators is on.
$form_id = 123; // Replace 123 with your form ID.
$approved_count = GFAPI::count_entries(
$form_id,
array(
'status' => 'active',
'field_filters' => array(
array(
'key' => 'is_approved',
'value' => GravityView_Entry_Approval_Status::APPROVED,
),
),
)
);Note: Not sure where to add this code? See Adding custom PHP code snippets to your website.
Count entries with SQL
These queries use form 123 and the default wp_ table prefix. This one counts approved entries:
SELECT COUNT(*)
FROM wp_gf_entry e
INNER JOIN wp_gf_entry_meta m
ON m.entry_id = e.id AND m.meta_key = 'is_approved' AND m.meta_value = '1'
WHERE e.form_id = 123 AND e.status = 'active';This one counts entries that aren’t approved, including those with no row:
SELECT COUNT(*)
FROM wp_gf_entry e
LEFT JOIN wp_gf_entry_meta m
ON m.entry_id = e.id AND m.meta_key = 'is_approved'
WHERE e.form_id = 123 AND e.status = 'active'
AND ( m.meta_value IS NULL OR m.meta_value <> '1' );Change the status #
See (Advanced) How to update entry approval status using PHP.