nf_get_fields_by_form_id

Get an array of our fields by form ID.

Description

(array) nf_get_fields_by_form_id( (int) $form_id, (string) $orderby = 'ORDER BY `order` ASC' ); 

The returned array has the field_ID as the key.

Returns (array)

$tmp_array

Parameters (2)

0. $form_id (int)
The form id.
1. $orderby — Optional. (string) => 'ORDER BY `order` ASC'
The orderby.

Usage

  1. if ( !function_exists( 'nf_get_fields_by_form_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/database.php'; 
  3.  
  4. // The form id. 
  5. $form_id = -1; 
  6.  
  7. // The orderby. 
  8. $orderby = 'ORDER BY `order` ASC'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = nf_get_fields_by_form_id($form_id, $orderby); 
  12.  

Defined (1)

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

/deprecated/includes/database.php  
  1. function nf_get_fields_by_form_id( $form_id, $orderby = 'ORDER BY `order` ASC' ) { 
  2. global $wpdb; 
  3.  
  4. $tmp_array = array(); 
  5. $field_results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".NINJA_FORMS_FIELDS_TABLE_NAME." WHERE form_id = %d ".$orderby, $form_id), ARRAY_A); 
  6. if ( is_array( $field_results ) && ! empty( $field_results ) ) { 
  7. foreach ( $field_results as $field ) { 
  8. $field_id = $field['id']; 
  9. $field['data'] = unserialize( $field['data'] ); 
  10. $tmp_array[ $field_id ] = $field; 
  11.  
  12. return $tmp_array;