ninja_forms_get_fields_by_form_id

The Ninja Forms ninja forms get fields by form id function.

Description

ninja_forms_get_fields_by_form_id( $form_id, (string) $orderby = 'ORDER BY `order` ASC' ); 

Parameters (2)

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

Usage

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

Defined (2)

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

/deprecated/includes/database.php  
  1. function ninja_forms_get_fields_by_form_id($form_id, $orderby = 'ORDER BY `order` ASC') { 
  2. global $wpdb; 
  3.  
  4. $field_results = $wpdb->get_results($wpdb->prepare("SELECT * FROM ".NINJA_FORMS_FIELDS_TABLE_NAME." WHERE form_id = %d ".$orderby, $form_id), ARRAY_A); 
  5. if(is_array($field_results) AND !empty($field_results)) { 
  6. $x = 0; 
  7. $count = count($field_results) - 1; 
  8. while($x <= $count) { 
  9. $field_results[$x]['data'] = unserialize($field_results[$x]['data']); 
  10. $x++; 
  11.  
  12. return $field_results; 
/includes/deprecated.php  
  1. function ninja_forms_get_fields_by_form_id($form_id, $orderby = 'ORDER BY `order` ASC') { 
  2.  
  3. $fields = Ninja_Forms()->form( $form_id )->get_fields(); 
  4.  
  5. $field_results = array(); 
  6. foreach( $fields as $field ) { 
  7. $field_results[] = array( 
  8. 'id' => $field->get_id(),  
  9. 'form_id' => $form_id,  
  10. 'type' => $field->get_setting( 'type' ),  
  11. 'order' => $field->get_setting( 'order' ),  
  12. 'data' => $field->get_settings(),  
  13. 'fav_id' => null,  
  14. 'def_id' => null,  
  15. ); 
  16. return $field_results;