WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Posts 2 Posts] How do I update meta on 'from' connection when 'to' is t

[Resolved] [Plugin: Posts 2 Posts] How do I update meta on 'from' connection when 'to' is t

  • 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.

    http://wordpress.org/extend/plugins/posts-to-posts/

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] [Plugin: Posts 2 Posts] How do I update meta on 'from' connection when 'to' is t’ is closed to new replies.