Support » Plugin: Posts 2 Posts » How to show the latest connected child post from parent post in loop

  • want to list latest child connected post ordered by parent post. Is it possible? Could anyone help me with that? I explain with an example: let’s say I have Dramas custom post type and an Episode custom post type, that are connected to Posts 2 Posts. In the Drama archive, I want to list all the dramas by their latest episode and want to show only one episode in the loop.

    I think it is maybe possible with each_connected(), but I don’t know how to order the $wp_query array to get this done.

    Thanks.

    I am using with such kind of code now

    global $post;

    $paged = ( get_query_var(‘page’) ) ? get_query_var(‘page’) : 1;

    $anime_series = array(
    ‘post_type’ => ‘drama’,
    ‘posts_per_page’ => 12,
    ‘paged’ => $paged,
    ‘page’ => $paged,
    ‘post_status’ => ‘publish’,
    ‘orderby’ => ‘post_date’,
    ‘order’ => ‘DESC’
    );

    $the_query = new WP_Query( $anime_series);

    $extra = array(
    ‘posts_per_page’ => 1,
    ‘post_status’ => ‘publish’,
    ‘orderby’ => ‘post_date’,
    ‘order’ => ‘DESC’
    );

    p2p_type( ‘drama_to_episode’ )->each_connected( $the_query, $extra, ‘episode’ );

  • The topic ‘How to show the latest connected child post from parent post in loop’ is closed to new replies.