Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Get connected posts of connected posts

  • Resolved WP Channel



    after reading the documentation, I can’t find to solve this problem :

    “how can I show connected posts of a connected posts of my current post”.

    Yes, I know it’s a bit strange. Let me explain in more details. I have custom post type for Hotel. Golfs are connected to Hotels. And Golfs-Courses are connected to Golfs.

    My goal is to show Golfs-Courses in the loop of my connected Golfs which appeared in the Hotel page (single-hotel.php).

    I tried something like this in the single-hotel.php file :

    If someone could help me, it would be awesome! Thanks.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author scribu


    Replace this:

    <?php $related = p2p_type( 'golfs_courses' )->get_related( get_queried_object_id() ); ?>

    with this:

    $related = new WP_Query( array(
      'connected_type' => 'golfs_courses',
      'connected_items' => $post->ID,
      'nopaging' => true,
    ) );

    And then you have to do something with $related. For example:

    while ( $related->have_posts() ) : $related->the_post();

    Awesome support for an awesome plugin… what else ? 🙂

    Plugin Author scribu


    I’m not sure what you mean. Were you expecting a free beverage as well? 😛


    I’ll be happy to offer it you if you come in France – for WordCamp for example. 😉

    Hi Scribu,

    another question related to the previous lines of code.

    After the endwhile; I’d like to insert

    <?php comments_template(); ?>

    But nothing shows… any idea?

    Plugin Author scribu


    I assume you have to call setup_postdata( $appropriate_post_object ); before that.

    PS: This is getting offtopic.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Plugin: Posts 2 Posts] Get connected posts of connected posts’ is closed to new replies.