So I have a one-to-many custom post type relationship. I have added a hook into 'transition_post_status' to note a change in post status. Specifically my issue is with moving post to the trash. I cannot identify the 'from' using get_posts().
Example Album -> Tracks. Tracks have length. Album has total length. I want to trigger recalculating album length when a track is trashed.
add_action( 'transition_post_status', 'recalc_album_length_hook', 10, 3 );
function recalc_album_length_hook( $n, $o, $post ){
if( $post->post_type != 'track' ) return;
$albums = get_posts( array('connected_types'=>'alb_tracks', 'connected_items'=>$post->ID) );
recalc_album_length( $albums[0]->ID );
}
Excuse any typos, hopefully the gist is clear. The $albums array is empty.