Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Formdiable Masterminds - count entries shortcode for https://formidable-masterminds.com/count-entries-shortcode/
<?php
add_shortcode( 'count_entries', 'fm_count_entry_records' );
function fm_count_entry_records( $atts ) {
global $wpdb;
$prefix = $wpdb->prefix;
$frm_items = $prefix . 'frm_items';
$frm_item_metas = $prefix . 'frm_item_metas';
$atts = shortcode_atts( array(
'field_id' => '0',
'field_key' => '',
'field_value' => '',
), $atts );
if ( !empty( $atts['field_key'] ) ) {
$field_id = FrmField::get_id_by_key( $atts['field_key'] );
} else {
$field_id = $atts['field_id'];
}
$meta_value = $atts['field_value'];
$sql = "SELECT count(*) FROM `{$frm_item_metas}` WHERE field_id = '{$field_id}' and meta_value = '{$meta_value}'";
$record_count = $wpdb->get_var( $sql );
return $record_count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment