nf_get_sub_count

Get a count of submissions for a form.

Description

(int) nf_get_sub_count( (int) $form_id, (string) $post_status = 'publish' ); 

Returns (int)

$count

Parameters (2)

0. $form_id (int)
The form id.
1. $post_status — Optional. (string) => 'publish'
The post status.

Usage

  1. if ( !function_exists( 'nf_get_sub_count' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/database.php'; 
  3.  
  4. // The form id. 
  5. $form_id = -1; 
  6.  
  7. // The post status. 
  8. $post_status = 'publish'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = nf_get_sub_count($form_id, $post_status); 
  12.  

Defined (1)

The function is defined in the following location(s).

/deprecated/includes/database.php  
  1. function nf_get_sub_count( $form_id, $post_status = 'publish' ) { 
  2. global $wpdb; 
  3.  
  4. $meta_key = '_form_id'; 
  5. $meta_value = $form_id; 
  6.  
  7. $sql = "SELECT count(DISTINCT pm.post_id) 
  8. FROM $wpdb->postmeta pm 
  9. JOIN $wpdb->posts p ON (p.ID = pm.post_id) 
  10. WHERE pm.meta_key = %s 
  11. AND pm.meta_value = %s 
  12. AND p.post_type = nf_sub 
  13. AND p.post_status = %s"; 
  14.  
  15. $count = $wpdb->get_var( $wpdb->prepare( $sql, $meta_key, $meta_value, $post_status ) ); 
  16.  
  17. return $count;