nf_add_relationship

Create a relationship between two objects.

Description

nf_add_relationship( (int) $child_id, (string) $child_type, (int) $parent_id, (string) $parent_type ); 

Parameters (4)

0. $child_id (int)
The child id.
1. $child_type (string)
The child type.
2. $parent_id (int)
The parent id.
3. $parent_type (string)
The parent type.

Usage

  1. if ( !function_exists( 'nf_add_relationship' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'ninja-forms/deprecated/includes/functions.php'; 
  3.  
  4. // The child id. 
  5. $child_id = -1; 
  6.  
  7. // The child type. 
  8. $child_type = ''; 
  9.  
  10. // The parent id. 
  11. $parent_id = -1; 
  12.  
  13. // The parent type. 
  14. $parent_type = ''; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = nf_add_relationship($child_id, $child_type, $parent_id, $parent_type); 
  18.  

Defined (1)

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

/deprecated/includes/functions.php  
  1. function nf_add_relationship( $child_id, $child_type, $parent_id, $parent_type ) { 
  2. global $wpdb; 
  3. // Make sure that our relationship doesn't already exist. 
  4. $count = $wpdb->query( $wpdb->prepare( 'SELECT id FROM ' . NF_OBJECT_RELATIONSHIPS_TABLE_NAME .' WHERE child_id = %d AND parent_id = %d', $child_id, $parent_id ), ARRAY_A ); 
  5. if ( empty( $count ) ) { 
  6. $wpdb->insert( NF_OBJECT_RELATIONSHIPS_TABLE_NAME, array( 'child_id' => $child_id, 'child_type' => $child_type, 'parent_id' => $parent_id, 'parent_type' => $parent_type ) );