WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] How do I update meta on 'from' connection when 'to' is t (3 posts)

  1. TCBarrett
    Member
    Posted 1 year ago #

    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/

  2. scribu
    Member
    Plugin Author

    Posted 1 year ago #

    I suppose you could use p2p_get_connections().

  3. TCBarrett
    Member
    Posted 1 year ago #

    Natch :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.