/** * Custom shortcode to display the total number of entries for a form. * * Basic usage: [wpf_entries_count id="FORMID" type="TYPE"] * * Realtime counts could be delayed due to any caching setup on the site * * @link https://wpforms.com/developers/how-to-display-the-total-number-of-entries/ */ function wpf_entries_count( $atts ) { // Pull ID shortcode attributes such as the type of entries to count $atts = shortcode_atts( [ 'id' => '', 'type' => 'all', // all, unread, read, or starred. ], $atts ); if ( empty( $atts[ 'id' ] ) ) { return; } $args = [ 'form_id' => absint( $atts[ 'id' ] ), ]; // What types of entries do you want to show? The read, unread, starred or all? 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' );
Skip to contentSkip to footer