• Resolved r1987

    (@r1987)


    Hello!

    This is a bit of a puzzle for me & I’m even doubting this is even possible in a simple way.

    Anyhow:

    1. I have two CPT called Performers and Productions.
    2. Performers also have an custom taxonomy called “Performer Field” with terms “Actor” “Dancer” “Musician”.
    3. Performers are attached to Productions. Where I just select the names.
    4.How to display the Performers outputed by their field on a single production page?

    Like
    Actors: Tom Hanks, John Smith
    Dancers: Mississipi Group, New York Dancers
    . . .

    http://wordpress.org/extend/plugins/cpt-onomies/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Ooh! A challenge! Here’s what I got. I hope it helps:

    if ( have_posts() ) : while ( have_posts() ) : the_post();
    
       // first, figure out which performers are tied to this production. you only need the IDs.
       $performers = wp_get_object_terms( get_the_ID(), 'performers', array( 'fields' => 'ids' ) );
    
       // then, get all the performer field terms
       $performer_fields = get_terms( 'performer_field' );
    
       // loop through each field
       foreach( $performer_fields as $field ) {
    
          // save performer data for printing
          $print_performers = array();
    
          // figure out which posts are tied to this specific field
          $field_objects = get_objects_in_term( $field->term_id, $field->taxonomy );
    
          // by comparing to our array of performer IDs, we can figure out which ones belong to this production AND to this specific taxonomy
          // if matches both logic, save for printing later
          foreach( $field_objects as $performer_id ) {
             if ( in_array( $performer_id, $performers ) )
                $print_performers[] = '<a href="' . get_permalink( $performer_id ) . '">' . get_the_title( $performer_id ) . '</a>';
          }
    
          // print list
          if ( $print_performers ) {
             ?><p><?php echo $field->name . ': ' . implode( ', ', $print_performers ); ?></p><?php
          }
    
       }
    
    endwhile; endif;
    Thread Starter r1987

    (@r1987)

    Wow Rachel!

    What a puzzle indeed!
    This is fantastic. As I already thought that may-be i should create extra cptonomies for these fields also and dump the traxonomies.

    Thanks a big time!

    You’re welcome!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CPTonomie terms according to custom taxonomy terms’ is closed to new replies.