The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. TCBarrett
    Posted 3 years 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.


  2. scribu
    Plugin Author

    Posted 3 years ago #

    I suppose you could use p2p_get_connections().

  3. TCBarrett
    Posted 3 years ago #

    Natch :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Posts 2 Posts
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic


No tags yet.