nf_update_object_meta

Function that updates a piece of object meta.

Description

(string) nf_update_object_meta( (string) $object_id, (string) $meta_key, (string) $meta_value ); 

Returns (string)

$meta_id

Parameters (3)

0. $object_id (string)
The object id.
1. $meta_key (string)
The meta key.
2. $meta_value (string)
The meta value.

Usage

  1. if ( !function_exists( 'nf_update_object_meta' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/functions.php'; 
  3.  
  4. // The object id. 
  5. $object_id = ''; 
  6.  
  7. // The meta key. 
  8. $meta_key = ''; 
  9.  
  10. // The meta value. 
  11. $meta_value = ''; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = nf_update_object_meta($object_id, $meta_key, $meta_value); 
  15.  

Defined (1)

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

/deprecated/includes/functions.php  
  1. function nf_update_object_meta( $object_id, $meta_key, $meta_value ) { 
  2. global $wpdb; 
  3.  
  4. if ( is_array( $meta_value ) ) { 
  5. $meta_value = serialize( $meta_value ); 
  6.  
  7. // Check to see if this meta_key/meta_value pair exist for this object_id. 
  8. $found = $wpdb->get_row( $wpdb->prepare( "SELECT id FROM ".NF_OBJECT_META_TABLE_NAME." WHERE object_id = %d AND meta_key = %s", $object_id, $meta_key ), ARRAY_A ); 
  9.  
  10. if ( $found ) { 
  11. $wpdb->update( NF_OBJECT_META_TABLE_NAME, array( 'meta_value' => $meta_value ), array( 'meta_key' => $meta_key, 'object_id' => $object_id ) ); 
  12. $meta_id = $found['id']; 
  13. } else { 
  14. $wpdb->insert( NF_OBJECT_META_TABLE_NAME, array( 'object_id' => $object_id, 'meta_key' => $meta_key, 'meta_value' => $meta_value ) ); 
  15. $meta_id = $wpdb->insert_id; 
  16.  
  17. return $meta_id;