Support » Plugin: Posts 2 Posts » each_connected and pagination

  • I have an project page in which I’m trying to get a listing of posts and their authors. Authors in this case have their own post type. So I’m trying to get two levels deep in this listing. Posts connected to the project and authors connected to the post.

    This works, but I can’t get pagination to work:

    p2p_type( 'post_to_project' )->each_connected( $wp_query, array(), 'post' );
    while ($wp_query->have_posts() ) : $wp_query->the_post();
    	p2p_type( 'post_to_author' )->each_connected( $post->post, array(), 'connected' ); // connected contains author_cpt's
    	foreach ( $post->post as $post ) : setup_postdata( $post );
    		get_template_part( 'content', 'excerpt' );
    if (function_exists('wp_pagenavi'))
    	wp_pagenavi( array( 'query' => $wp_query) );

    and this works with pagination, but the author doesn’t show.

    $paged = get_query_var('paged') ? get_query_var('paged') : 1;
    $connected_posts = new WP_Query( array(
      'connected_type' => 'post_to_project',
      'connected_items' => get_queried_object(),
      'posts_per_page' => 6,
      'paged' => $paged
    ) );
    // Display connected posts
    if ( $connected_posts->have_posts() ) :
    	while ( $connected_posts->have_posts() ) : $connected_posts->the_post();
    		get_template_part( 'content', 'excerpt' );
    	if (function_exists('wp_pagenavi'))
    		wp_pagenavi( array( 'query' => $connected_posts) );

    I’m trying to get the authors to show with pagination working. Any assistance would be much appreciated.


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