Function to count entries in filtered view

By: James Knight | Asked: 10/29/2021
ForumsCategory: Code HelpFunction to count entries in filtered view
James Knight asked 2 years ago
Hi everyone, has anyone come across a way to count how many entries are currently in a filtered view?   I'm using BuddyBoss which includes social Groups but no custom fields. Because of this I'm embedding FF into a widget and using that to allow users to add custom fields. I've got this all working correctly and in my view it references the Group ID provided in a function to a field as a default value. From there I can filter using that field to make sure that the page/ Group the user is looking at matches the group ID to it's respective field:  
// BuddyBoss (Groups)- Adds the current group ID to a field in Formidable Forms.
add_filter('frm_get_default_value', 'bb_group_id_finder', 10, 3); 
function bb_group_id_finder( $new_value, $field, $is_default ) {
  $group_id = bp_get_current_group_id();  // Finds the ID of the group that's currently visible on the page.
  if ( $field->id == 28 && $is_default ) { // 28 is the field we're writing to
    $new_value = $group_id; // Switch the value to be our called Group ID
  return $new_value;

// BuddyBoss (Groups)- Use the current Group ID to filter our view in Formidable Forms.
add_filter('frm_filter_where_val', 'bb_group_id_to_ff_view_filter', 8, 2);
function bb_group_id_to_ff_view_filter( $where, $args ) {
  $group_id = bp_get_current_group_id();  // Finds the ID of the group that's currently visible on the page.
  if ( $args['display']->ID == 164 && $args['where_opt'] == 28 && isset( $group_id ) ) {
    $where = $group_id;
  return $where;
  The final piece of the puzzle is checking to see if the view has a matching entry. If it does, we show the resulting entry and place an edit button below. If there isn't an entry, we'd like to just show the form or a button to edit instead. Is there a function that I could call within my functions.php that could help to handle that?
2 Answers
Chris AdamsChris Adams answered 2 years ago
Hi James, The [entry_count] shortcode will show you the number of entries in a filtered view when placed in the Before Fields or After Fields section of the view. If you have pagination turned on it will show you the total across all pages, not the total for the current page. By the sound of it though this might not be what you're looking for? If you want to filter a view based on the value of a field (and you can't do it with the standard filters) you can do it with the frm_where_filter or frm_filter_where_val hook.
James Knight answered 2 years ago
Thanks for getting back to me! So unfortunately using [entry_count]  wouldn't work for my use case as if there's no entries the Before and After field wouldn't work... Your response got me thinking though. I could just add the shortcode for the form to the no-entries message and what I'm trying to achieve works that way instead! For some reason I was under the impression that the shortcodes wouldn't work in those fields.   Love the Formidable community. :)
Chris AdamsFDM Digital replied 2 years ago

Glad i could help out 🙂

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community