• wp-MeMeMe

    (@wp-mememe)


    I have code that works in a single file (archive.php) but loses the connection data if I split it the loop out into a loop.php file and call it with get_template_part (‘loop’)

    How do I avoid losing the connections when using a template part?

    In more detail, here is what i’m doing:
    I use this custom query

    $args = array(
    	'post_type' => $post_type_name,
    	'post_parent' => 0,
    	'orderby' => 'title', 'order' => 'ASC'
    	);
    
    $wp_query = new WP_Query( $args );

    and set up a bunch of connections like this

    global $wp_query;
    p2p_type( 'people_to_places' )->each_connected( $wp_query, array(), 'place_people' );

    Then call them in the loop like this like this:

    <div class="place-link place-narrow" >
    	<?php
    	echo '<strong>Related:</strong> ';
            foreach ( $post->place_people as $post ) : setup_postdata( $post );
    	        the_title();
    	endforeach;
    	wp_reset_postdata(); // set $post back to original post
    	?>
    </div>

    It all works fine if I have all the code in a single file, but when I put that last bit in loop.php and call it with get_template_part, the connections are empty.

    http://wordpress.org/extend/plugins/posts-to-posts/

  • The topic ‘each_connected and get_template_part’ is closed to new replies.