• Resolved jvarn1

    (@jvarn1)


    Let’s say I have post-types called: “specialist”, “field”, and “organization”. Each specialist has a connected field and organization, but field and organization have no direct connection.

    On the single page for “field”, I can make a list of “specialist” pages who are connected to the current “field” page, and using the code provided on the github wiki for related posts, I can also list a reciprocal list of other connected “field” pages for each of the listed “specialist” pages. S

    However, I’d like instead on the “field” page to list connected “specialist” pages as above, except under each one then find the “organization” pages connected to that “specialist” page. I’ve only managed to do this by nesting a second query within the loop using ‘connected_items’ => $post->ID, but I’m sure there’s a better way.

    Here’s the code I’ve got working so far in single-field.php:

    <?php // SPECIALISTS IN THIS FIELD
    // Find connected pages
    $connected = new WP_Query( array(
      'connected_type' => 'specialist_to_field',
      'connected_items' => get_queried_object_id(),
      'nopaging' => true,
    ) );
    
    // Display connected pages
    if ( $connected->have_posts() ) :
    ?>
    	<h3>Specialists:</h3>
    	<ul>
    		<?php while ( $connected->have_posts() ) : $connected->the_post(); ?>
    			<li><b><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><b></li>
    			<?php // ORGANIZATIONS RELATED TO EACH SPECIALIST
    			$related = new WP_Query( array(
    			  'connected_type' => 'specialist_to_organization',
    			  'connected_items' => $post->ID,
    			  'nopaging' => true,
    			) );?>
    
    				Works at:
    				<?php while ( $related->have_posts() ) : $related->the_post(); ?>
    				<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    				<?php endwhile; ?><br/>
    
    		<?php endwhile; ?>
    	</ul>
    
    	<?php
    	// Prevent weirdness
    	wp_reset_postdata();
    
    endif;
    ?>

    https://www.ads-software.com/extend/plugins/posts-to-posts/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: Posts 2 Posts] Listing connections of connections in third’ is closed to new replies.