WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
each_connected and pagination (1 post)

  1. Brian Cruikshank
    Member
    Posted 4 months ago #

    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' );
    	endforeach;
    endwhile;
    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' );
    	endwhile;
    	if (function_exists('wp_pagenavi'))
    		wp_pagenavi( array( 'query' => $connected_posts) );
    endif;

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

    Thanks,
    Brian

    https://wordpress.org/plugins/posts-to-posts/

Reply

You must log in to post.

About this Plugin

About this Topic

  • RSS feed for this topic
  • Started 4 months ago by Brian Cruikshank
  • This topic is not resolved
  • WordPress version: 3.8.1