Skip to content

Instantly share code, notes, and snippets.

@jaredatch
Created October 12, 2020 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredatch/a6f09902e6bf606658c1813461161c11 to your computer and use it in GitHub Desktop.
Save jaredatch/a6f09902e6bf606658c1813461161c11 to your computer and use it in GitHub Desktop.
Display WPForms entries count
<?php
/**
* Custom shortcode to display WPForms form entries count for a form.
*
* Basic usage: [wpf_entries_count id="FORMID" type="TYPE"].
*
* @param array $atts Shortcode attributes.
*
* @return string
*/
function wpf_entries_count( $atts ) {
// Pull ID shortcode attributes.
$atts = shortcode_atts(
[
'id' => '',
'type' => 'all', // all, unread, read, or starred.
],
$atts
);
if ( empty( $atts['id'] ) ) {
return;
}
$args = [
'form_id' => absint( $atts['id'] ),
];
if ( $atts['type'] === 'unread' ) {
$args['viewed'] = '0';
} elseif( $atts['type'] === 'read' ) {
$args['viewed'] = '1';
} elseif ( $atts['type'] === 'starred' ) {
$args['starred'] = '1';
}
return wpforms()->entry->get_entries( $args, true );
}
add_shortcode( 'wpf_entries_count', 'wpf_entries_count' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment