All these are to be called on 'init' action with the priority of 12 or later
Before init 12 there are no relations registered
This is to get Relation object by its ID (https://prnt.sc/zCOroTie86bL)
(object of this class \jet-engine\includes\components\relations\relation.php)
Necessary to work with relation
$relation = jet_engine()->relations->get_active_relations( $rel_id );
These are to get parents/children of the Post/CCT/Term/User from above-mentioned relation object
$object_id - ID of the object for which you need to get parents/children;
$field - 'ids' to return array of related items IDs, 'all' to return array of rows from database
$field = 'ids';
$related_ids = $relation->get_parents( $object_id, $field );
$related_ids = $relation->get_children( $object_id, $field );
Returns related items for given object. Automatically detects - we need to get children or parent items by object.
pass object as a first argument, not object id
$related_ids = $relation->get_related_items_for_object( $object );
Set relation update context - 'parent' or 'child'
$relation->set_update_context( 'parent' );
Update relation
$relation->update( $parent_object_id, $child_object_id );
if $parent_object_id is empty - delete all rows for current relations which have $child_object_id
if $child_object_id is empty - delete all rows for current relations which have $parent_object_id
CAUTION: if both empty - all rows for the relation will be deleted
$clear_meta - true / false, whether to delete associated meta; default true
$relation->delete_rows( $parent_object_id, $child_object_id, $clear_meta )
$relation->get_meta( $parent_object_id, $child_object_id, $meta_key );
$relation->update_meta( $parent_object_id, $child_object_id, $meta_key, $meta_value );
$relation->delete_meta( $parent_object_id, $child_object_id, $meta_key );
add_action( 'jet-engine/relation/update/before', function( $parent_object_id, $child_object_id, $relation ) {
}, 0, 3 );
runs before connecting items with relation
$parent_object_id, $child_object_id - IDs of items
$relation - object of Relation class
add_action( 'jet-engine/relation/update/after', function( $parent_object_id, $child_object_id, $item_id, $relation ) {
}, 0, 4 );
runs after connecting items with relation
$parent_object_id, $child_object_id - IDs of items
$item_id - ID of inserted record
$relation - object of Relation class
Very helpful. Thanks.
I use the last action. It works for the initial connecting but not if I change the meta field value of a existing relation.
My usecase is:
I have a "Job CCT". The relation is one to many between Job CCT and user. There is one job and many people can apply for it. The relation has got a meta field called "status" where I select "applied", "meeting", "canceled" etc.
I want to fire actions if this meta field value changes. If the status changes from applied to canceld, I want to send an e-mail.
Which hook can I use for this?
Thank you very much.
EDIT:
I think I found a solution: