• Hello all,

    I’m stuck on some code for days now, no matter what I try, I can’t seem to get it to work. I inherited this project for a non-profit organisation and managed to change all they requested except for this small part. It is important for me that I learn from this.

    I have the following code but want to add a connection to another p2p and get some information from there to display as well.

    <?php $eventlist = array(  'post_type' => 'event',
                                'nopaging' => true,
                                'meta_key' => '_event_start_date',
                                'orderby' => 'meta_value',
                                'order' => 'ASC' );
    $loop = new WP_Query( $eventlist );
    
    p2p_type( 'events_to_event_info_pages' )->each_connected( $loop );
    
    while ( $loop->have_posts() ) : $loop->the_post();
            $myID = get_the_ID();
            $EM_Event = em_get_event($myID, 'post_id');
            $myDates = $EM_Event->output("#_EVENTDATES");
            $myEndDate = substr($myDates, -10);
            if (date("Ymd", strtotime($myEndDate))>date("Ymd")) :
               $myLocation = $EM_Event->output("#_LOCATIONNAME");
               $myTown = $EM_Event->output("#_LOCATIONTOWN");
               $myStartDate = $EM_Event->output("#d-#m-#Y");
    
               if (get_field('additional_dates')) {
                  $dates = array();
                  while(has_sub_field('additional_dates')) {
                  $dates[] = get_sub_field('date');
                  }
               }
    									   else {
                  $dates = false;
               }
    
              $count = count($dates);
    
    $connected = false;
              foreach ( $post->connected as $post ) : setup_postdata( $post );
    $connected = true;
    
    $myPageID = $post->ID;
    $myTitle = get_the_title();
    $myLink = get_permalink();
    $myDescription = get_field('description_excerpt');
    $myContent = strip_tags(get_field('description', $post->ID));
    $myContent = '<p>'.shorten_description($myContent, 300).'</p>';
    
    $terms = get_the_terms($post->ID, 'event_info_pages_categories');
    $myCategory = '';
    $myCategorySlug = '';
    
    if ($terms) {
    foreach ( $terms as $term ) {					$myCategory .= $term->name .', ';
    $myCategorySlug .= $term->slug .' ' ;
    }
    }
    								$terms = get_the_terms($post->ID, 'event_info_pages_disciplines');
    if ($terms) {
    															foreach ( $terms as $term ) {								$myDiscipline = $term->name;						$myDisciplineSlug = $term->slug;
    }
    }
    $images = get_field('gallery', $post->ID);
    $image = $images[0];
    
    endforeach; ?>                      
    
    <?php // Prevent weirdness
      wp_reset_postdata(); ?>

    I know it’s a lot to ask but if someone could just point me in the right direction. I dun mind spending time figuring things out but after several days of no progress it would be nce if at least i could make a small step forward.

    1. How do I add another p2p link? like this under the existing p2p link? p2p_type( 'my_p2p_name_here' )->each_connected( $myName );

    2. How can I pull the information from this new link. perhaps I can figure this out/get this to work if he p2p-link works without any problems.

    Any help would be much appreciated.

    wlp.

    https://ww.wp.xz.cn/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
  • Thread Starter wlp80

    (@wlp80)

    Sorry for the messy code layout in the above post but can’t seem to edit this any longer…

Viewing 1 replies (of 1 total)

The topic ‘multiple connections’ is closed to new replies.