Advertisement
Guest User

RelationShips Fix

a guest
Nov 19th, 2021
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.75 KB | None | 0 0
  1.     /**
  2.      * Delete all relationships to an object.
  3.      *
  4.      * @param int    $object_id ID of the object metadata is for.
  5.      * @param string $type      The relationship type.
  6.      * @param string $target    The relationship target.
  7.      */
  8.     protected function delete_object_relationships( $object_id, $type, $target ) {
  9.         global $wpdb;
  10.  
  11.         $sql = $target
  12.             ? "DELETE FROM $wpdb->mb_relationships WHERE `type`=%s AND `$target`=%d"
  13.             : "DELETE FROM $wpdb->mb_relationships WHERE `type`=%s AND (`from`=%d OR `to`=%d)";
  14.  
  15.         if($target):
  16.             $wpdb->query(
  17.                 $wpdb->prepare(
  18.                     $sql,
  19.                     $type,
  20.                     $object_id
  21.                 )
  22.             );
  23.         else:
  24.             $wpdb->query(
  25.                 $wpdb->prepare(
  26.                     $sql,
  27.                     $type,
  28.                     $object_id,
  29.                     $object_id
  30.                 )
  31.             );
  32.         endif;
  33.  
  34.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement