Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Tokant

    (@tokant)

    Okay, i found out exactly what to implement, as described here:
    https://github.com/scribu/wp-posts-to-posts/wiki/Related-posts

    $related = p2p_type( ‘posts_to_pages’ )->get_related( get_queried_object() );

    But how do i use this in the following WP_Query?

    <?php
    // Find connected pages
    $connected = new WP_Query( array(
    'connected_type' => 'galleries_to_exhibitions',
    'connected_items' => 'any',
    'connected_direction' => 'from',
    'nopaging' => true
    ) );
    // Display connected pages
    if ( $connected->have_posts() ) :
    ?>
    code for each exhibition ...
    <?php
    // Prevent weirdness
    wp_reset_postdata();
    endif;
    ?>

    Thanks!

    Thread Starter Tokant

    (@tokant)

    Problem solved. For others who need to display related posts, use this:

    <?php
    // Find connected posts
    $related = p2p_type( 'galleries_to_exhibitions' )->get_related( get_queried_object() );
    // Display related posts
    if ( $related->have_posts() ) :
    while ( $related->have_posts() ) : $related->the_post(); ?>
    code for each exhibition ...
    <?php
    endwhile;
    // Prevent weirdness
    wp_reset_postdata();
    endif;
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Related posts’ is closed to new replies.