Site icon Hip-Hop Website Design and Development

WP Function does not trigger on Webhook API Call

I have created a function that triggers and connect parent post with Child post based on a Custom Meta Field value. If Meta field value of an existing Parent post matches with the newly created child post then function automatically connect the parent post with child post. and this function works perfectly If I am creating the child post using WP Admin area or using a Frontend Post Submission form. But If I am creating the Child Post usign a Webhook Incoming data then function doesn’t trigger. and it doesn’t connect the parent post based on the Custom Meta field "wpcf-patient-id".

I am using WP Webhooks Pro to receive data from a external source that includes the post title, content, wpcf-patient-id, and few other details. Each time Webhook receives a payload data, it creates a new post using the received payload data. But the function doesn’t trigger at all.

So if anyone can help me make it work, Please suggest the possible solution.

add_action( 'save_post', 'assign_parent_patient_func', 100,3 );
function assign_parent_patient_func( $post_id, $post, $update ) {
    
    // Only set for post_type = post!
    if ( !in_array($post->post_type, array('qev-attachment', 'note')) ) {
        return;
    }
      
    $patient_id = get_post_meta($post_id, 'wpcf-patient-id', true); 
    if($patient_id){
        $client_ids = get_posts( array(
            'post_type' => 'client',
            'meta_key' => 'wpcf-patient-id', 
            'meta_value'=> $patient_id,
            'fields' => 'ids'
        ));
        if(isset($client_ids[0])){
            $client_id = $client_ids[0];
            if($post->post_type == 'qev-attachment'){
                toolset_connect_posts('client-attachment', $client_id, $post_id);
            }
            if($post->post_type == 'note'){
                toolset_connect_posts('client-note', $client_id, $post_id);
            }
        }
    }
}